I have created a table that has a column with the name started of type datetime. I was very surprised to see this turn blue when I copied my select statement into management studio. When looking at the list of reserved words for SQL in the Microsoft documentation (see here), I cannot find the word started.
What is it? What does it do?
A very old SSMS problem.
I'm afraid M$ doesn't care about some tokens treated as keywords.
See this.
I don't think so. There is no keyword exist with the name started.
I was able to create table
SQLFiddle Demo
Related
I'm used to scripting in Python or Matlab, and my first couple hours with SQL have been infuriating. I would like to make a list of columns appear on the screen in any way, shape, or form; but when I use commands like
select *
from "2Second Log.dbo.TagTable.Columns"
I keep getting the error:
Invalid column name '[the first column in my table]'.
even though I never explicitly asked for [the first column in my table], it found it for me. How can you correctly identify the first column name, and then still claim it's invalid!? Babies will be strangled.
This db was generated by Allen Bradley's FactoryTalk software. What I would really like to do is produce an actual list of "TagName" strings...but I get the same error when I try that. If there were a way to actually double click the table and open it up and look at it (like in Matlab), that would be ideal.
Echoing juergen's suggestion in the comment above. It looks like you're running the query on the master database, not the 2Second Log database that actually has your table. (You can tell this by looking at the database in the dropdown in the top left of your screenshot). Two things you can do:
Change the dropdown in the top left to 2Second Log. This will target your query to a different database
Put your database name in brackets as suggested by juergen i.e. select * from [2Second Log].dbo.TagTable
As an side, if you're looking for a good SQL tutorial, I highly recommend the Mode SQL tutorial. It's a fantastic interactive platform to get your SQL feet wet.
always use brackets when names/field have spaces or dashes.
select * from [2Second Log].dbo.TagTable
Not quite sure what these are to be honest. I am looking at someone else's SQL query and they have SELECT statements which look like this:
SELECT
Something,
Something
FROM
MyTable(DEFAULT, DEFAULT, DEFAULT)
And Another which looks like this:
SELECT
Something,
Something
FROM
MyTable(NULL)
Christ, when I do a SELECT statement, I only put the table name there and that's it.
Could someone please tell me what the (DEFAULT, DEFAULT, DEFAULT) would be used for? and also the (NULL) - I'm sure there are many more of these once I know what they are.
My apologies if this is a duplicate question, but I couldn't seem to find an answer anywhere.
Thanks!
Mike
It appears that MyTable(DEFAULT, DEFAULT, DEFAULT) is a table-valued function call. This function has three parameters, and all these parameters should take default values.
In Management Studio, Look under Programmability->Functions->Table-valued Functions. There you will see the definition of the function.
I have a foreign key (IdForign), and always use it in where clause.
I have three fields:
Id
Name
IdForign
How can i create the index for the Name field?
(IdForign, Name) or just one for IdForign and other for Name?
Thanks!!
If I undertand correctly your question, you need to create an Index only for IdForign, because it's the one you use in the where
UPDATE
As per your comment, if you are using both fields I suggest you to use an index with Name and IdForign
Read this. It should give you some tips on indexing with Sql Server
The basic systax, which it seems is all you are asking for is:
CREATE INDEX yourIndexName ON yourTableName (yourFieldName);
This is also assuming you mean Microsoft SQL Server. See here for the MSDN documentation.
I hope this helps.
I have a simple Ms-Access database with one table named Student and it has two columns ID and Name.
When I the database in Access and enter the query
select * from Student where Name like 'J%'
in its SQL view, it gives an empty resultset.
But the table has a Name called John.
I tried with other databases and tables also with like-queries, but none works.
Can anyone please tell if there is any special reason for this???
Thank you
Edit:
The same query works with c sharp code
What you need is
select * from Student where Name like 'J*'
or possibly (because I don't have access handy to check, possibly either will work)
select * from Student where Name like "J*"
The * is the wild card character for MsAccess
From my experience in the past... yes access syntax has some minor difference that make even simple things a trouble.
I don't remember how but check around a way to make access show the sql from some results you retrieved in a graphical way, there must be some show sql button somewhere.
Once there examine carefully the sql syntax, then test your sql in access' editor.
So the main idea is let access show you the way!
When creating a new table in SSMS - right click on the "Tables" node, choose "New Table..." - the default definition for a new column is nchar(10).
Can I change that? Let's say I would like the default column definition to be varchar(5) whenever someone creates a new table.
I can't find any sort of option to change that, I'm thinking maybe it's a registry setting?
In the Registry:
Path - HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell\DataProject
Name - SSVDefaultColumnType
Also look at SSVDefault*Length (e.g. SSVDefaultCharLength) to set the length.
All caveats about changing the registry apply.
Thanks for that. One small thing: when there have been multiple installationss/ versions of SSMS installed, it's necessary to ensure that they right versions of the keys are changed.
Seems obvious, but I got caught out.
You can't. Actually, you can: see Darryl Peterson's answer
To be honest, you're quicker to use CREATE TABLE in a query windows and type it all manually. You pick the syntax up quick enough.
To start, you could look at View..Template Explorer. There is a "Create Table" template.