sql 外键设置

来源:百度知道 编辑:UC知道 时间:2024/07/04 02:28:26
use TestDB
go
if exists(select name from sysdatabases where name='TestDB')
drop database TestDB
create database TestDB
on
(
name=TestDB_data,
filename='E:\TestDB\TestDB_data.mdf',
size=5
)
log on
(
name=TestDB_log,
filename='E:\TestDB\TestDB_log.ldf',
size=5
)
go
--use TestDB
--drop table employee
--drop table project
--go
create table employee
(
emp_id int primary key,--员工编号,主键
emp_name Varchar(50),--员工姓名*/
emp_sex Varchar(50),/*姓名*/
department Varchar(50),/*所属部门*/
salary Money /*工资*/
)
go
create table project
(
pro_id int primary key,/*项目编号*/
pro_name varchar(50) ,/*项目名称*/
pe_id int,--负责人编号, 设置为外键
customer int,/*客户编码*/
start_date Datetime,/*开始日期*/
end_date Datetime/*结束日期*/

)
go
将项目数据表的字段“负责人编号”设为员工数据表中”员工编号”字段的一个外键
帮我看看下下面哪里错了呢

代码没有任何问题,在查询分析器中能顺利通过。请在查询分析器再重新试试

you should use another name instead user
for example User_table or userTable.

"user" is the key word in the ms-sql server is reserved..