sql server 2000怎样给表创建外键约束?

来源:百度知道 编辑:UC知道 时间:2024/05/24 18:04:09

--主键约束如下:比如student表的id为例
alter table student add
constraint PK_Student_Id primary key (id);

--外键约束如下:比如student表id位主键,score为子表scoreId为外键
alter table score add
consraint FK_Score_ScoreId foreign key(scoreId) references student(id);

希望对你有帮组.!

在查询分析里执行

create table t1(ID int primary key)

create table t2(t1_ID int foreign key references t1(ID))

或在企业管理里
设计表—右健—关系(选择表和列)

要建立约束的表->右键单击->表设计器->右键约束->里面加入条件即可