I have a table with a column name called "index"
select id, index
from item;
gives an error:
Msg 1018, Level 15, State 1, Line 1 Incorrect syntax near 'index'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See SQL Server Books Online for proper syntax.
How can I do a select on a column named index? I'm using sqlserver 2008-R2
Columns with one or more of the following characteristics are good candidates for indexing: Values are unique in the column, or there are few duplicates. There is a wide range of values (good for regular indexes). There is a small range of values (good for bitmap indexes).
To see the index for a specific table use SHOW INDEX: SHOW INDEX FROM yourtable; To see indexes for all tables within a specific schema you can use the STATISTICS table from INFORMATION_SCHEMA: SELECT DISTINCT TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.
The IN clause becomes an equality condition for each of the list and will use an index if appropriate.
Use square brackets to quote reserved words:
select id, [index]
from item
See also the documentation on Delimited Identifiers.
Put reserved words in brackets:
select id, [index]
from item
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With