alter table 单位表
add constraint pri_id primary key(id)
go
alter table 其它表
add constriant for_id foreign key (id) references 单位表(id) on delete cascade
on update cascade
go
add constraint pri_id primary key(id)
go
alter table 其它表
add constriant for_id foreign key (id) references 单位表(id) on delete cascade
on update cascade
go
主,外键没用过,请问删除,修改主键单位表的一条记录时,要先判断它是否已经被使用.要怎样判断.
create table t1(A int primary key, B int)
insert into t1 select 1,100
insert into t1 select 2,200
go
create table t2(A int not null,C int)
go
alter table t2
add constraint for_t foreign key(A) references t1(A)
go
add constraint pri_id primary key(id)
go
alter table 其它表
add constriant for_id foreign key (id) references 单位表(id) on delete cascade
on update cascade
go