sql - 选择列名为 "index"的表

标签 sql sql-server sql-server-2008 sql-server-2008-r2

我有一个表,其列名为“index”

select id, index
from item;

出现错误:

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.

如何对名为索引的列进行选择?我正在使用 sqlserver 2008-R2

最佳答案

使用方括号引用reserved words :

select id, [index]
from item

另请参阅 Delimited Identifiers 的文档.

关于sql - 选择列名为 "index"的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8387305/

相关文章:

sql-server - NVARCHAR(MAX) - 作为 SQL 存储过程输出参数

sql - 使用列名称取消透视

c# - 如何将表值参数传递给 .NET Core 中的 Dapper?

sql-server - Backup-SQLDatabase cmdlet 中的超时问题

c# - 如何从 Windows 服务访问 SQL 数据库?

sql-server - 数据库表中 bool 列的命名

sql-server - 如何使用 SQL Server 中的存储过程在单个查询中插入多行

sql闭环关系;会出什么问题?

MySql存储过程,如何用CONCAT插入多个变量

python - 一个模型如何可以有多个键,并以相同类型的模型作为值?