这里的 primary key 与 foreign key 咋解决???

sbxlj 2004-09-14 05:21:45
create table customer
(custid int not null
check ( custid>0),
name char(20) not null
check(name <>' '),
shipline1 varchar(30) not null
default ' ',
...............

constraint customerpk primary key ( custid) ,
constraint customerstatus check ( ( status<>' ')or (creditlimit is null)))
这个表最后一句是什么意思?
上面这个表能成功创建,但下面这个表要用上面表的 custid 做外键就会出错
create table sale
( orderid int not null,
saledate date not null,
saletotal money not null,
custid int not null,
constraint salepk primary key (orderid )
constraint salecustfk foreign key (custid)
reference customer (custid))
错误提示:在关键字 'constraint' 附近有语法错误。
该怎么办?


...全文
102 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sbxlj 2004-09-14
  • 打赏
  • 举报
回复
唉,劣质书害人啊,
我看的是电子版的书,
它的references 少了个s 害死我了!!!
lsxaa 2004-09-14
  • 打赏
  • 举报
回复
FOREIGN KEY 是外键,要指出外键所在的表名

CONSTRAINT FOREIGN KEY REFERENCES 外键所在的表名 ( custid )
sbxlj 2004-09-14
  • 打赏
  • 举报
回复
错误行在有frogein key 的那行
constraint salecustfk foreign key (custid)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧