用触发器建立表的主键和外键的关系 比如说 a 表中有一个id 字段 b表中也有一个id字段 怎样用触发器建立这两个表的主外键关系 create table a(id int,name int) create table b(id int,name int) create trigger waijian on a for insert ,update as begin if exists (select id from inserted where id not in(select id from b)) begin raiserror('外键约束',16,1) rollback tran end end
比如说 a 表中有一个id 字段 b表中也有一个id字段
怎样用触发器建立这两个表的主外键关系
create table a(id int,name int)
create table b(id int,name int)
create trigger waijian
on a
for insert ,update
as
begin
if exists (select id from inserted where id not in(select id from b))
begin
raiserror('外键约束',16,1)
rollback tran
end
end