我正在使用Microsoft的SQL Server 2012,并使用另一个表的主键作为外键创建一个表,但它表示存在语法错误
CREATE TABLE [dbo].[STUDENT]
(
STUDENT_ID int not null Identity,
SCHOOL_ID INT NOT NULL,
CONSTRAINT PKEY PRIMARY KEY (STUDENT_ID),
CONSTRAINT FKEY FOREIGN KEY (USER_ID) REFERENCES USER (USER_ID)
);
它给了我sql80001 error
请帮助
答案 0 :(得分:5)
USER
是reserved keyword in SQL Server。使用[]
来转义名称
CREATE TABLE [dbo].[STUDENT]
(
STUDENT_ID int not null Identity,
SCHOOL_ID INT NOT NULL,
CONSTRAINT PKEY PRIMARY KEY (STUDENT_ID),
CONSTRAINT FKEY FOREIGN KEY (USER_ID) REFERENCES [USER] (USER_ID)
)