sql 添加外键语句

来源:百度知道 编辑:UC知道 时间:2024/06/03 15:46:25
在sql server2000,对已建好的表,我需要添加外键,如何用语句实现?注意哦,我想要通过语句实现

使用以下sql语句: alter table 需要建立外键的表 add constraint 外键名字 foreign key references 外键表(外键字段) ,

alter table 需要建立外键的表 add constraint 外键名字 foreign key (需要建立外键的字段名) references 外键表(外键字段)

alter table 表名 add constraint 约束名 约束内容

例:
alter table test add constraint CK_column check(column<100)