0
Create      Table       employees (
emp_id          char(5)         not null,
hourly_pay      integer         not null,
emp_name        varchar(30)     not null,
emp_address     varchar(50)     not null,
gender          char(1)         not null,
email           varchar(30)     null,
contact_info    integer         not null,
outlet_id       char(5)         null,
supervisor_id   char(5)         null,
job             varchar(15)     not null,
PRIMARY     KEY (emp_id)
FOREIGN     KEY (supervisor_id) 
REFERENCES  employees(emp_id)
)

数据如上图。SQL Server 2008 不断抛出“关键字'FOREIGN'附近的语法不正确”的错误。

4

1 回答 1

0

你少了一个逗号。

Create      Table       employees (
emp_id          char(5)         not null,
hourly_pay      integer         not null,
emp_name        varchar(30)     not null,
emp_address     varchar(50)     not null,
gender          char(1)         not null,
email           varchar(30)     null,
contact_info    integer         not null,
outlet_id       char(5)         null,
supervisor_id   char(5)         null,
job             varchar(15)     not null,

PRIMARY     KEY (emp_id),
------------------------^

FOREIGN     KEY (supervisor_id) REFERENCES  employees(emp_id)
)
于 2012-07-21T16:37:45.463 回答