rt,比如说我想建一个课程表,有列课程ID,课程名称,先行课。那么我要约束先行课必须在课程ID里取值。。。
------解决方案--------------------
加个check约束
------解决方案--------------------
create table tb
(id int not null,
name varchar(10) not null,
pid int null,
constraint PK_tb primary key nonclustered (id)
)
go
alter table tb
add constraint FK_self foreign key (pid)
references tb (id)
go
alter table tb
add constraint CHK_tb CHECK(pid<>id)