如何在sql server中使用列名'used'

时间:2013-10-01 19:20:29

标签: sql-server

我有一个从MySQL迁移到SQLServer的数据库。表的一个列名是use。我怎么能写我的插入语句不抛出错误呢?我收到了错误:

Msg 156, Level 15, State 1, Line 4830
Incorrect syntax near the keyword 'use'.

我的插入内容类似于:

insert into foo (id, use, some_other_attrs) values(1, fun, other_stuff);

3 个答案:

答案 0 :(得分:8)

use是一个reserved keyword(提示就在错误信息中!),它允许您更改数据库上下文(例如USE master;)。您不应该使用保留字作为标识符(表名,列名,数据库名,用户等)。

您需要修复列名称(我建议使用更具描述性和自我记录的内容)或用方括号括起来(告诉SQL Server忽略它是关键字)。另外,please always use the schema prefix on objects

INSERT dbo.foo(id, [use], ...) SELECT 1, 'fun', ...;

答案 1 :(得分:5)

我想你必须把名字放在[use]

insert into foo (id, [use], some_other_attrs) values(1, fun, other_stuff);

旁注:不希望使用Reserve keyword作为列名

答案 2 :(得分:2)

[]

包裹它
insert into foo (id, [use], some_other_attrs) values(1, fun, other_stuff);

远离列名的保留字

http://technet.microsoft.com/en-us/library/ms189822.aspx

相关问题