做这样的foreign key约束不行的 现在的意思是table1的 编号、卡号 必须同时在table2 table3中都有 CREATE TRIGGER T_insert_table1 ON table1 FOR INSERT AS if not exists (select * from (select 1 b from table2 a join inserted b on a.编号=b.编号 and a.卡号=b.卡号 union select 1 b from table3 c join inserted b on c.编号=b.编号 and c.卡号=b.卡号) a) begin print 'error' rollback tran end
现在的意思是table1的 编号、卡号 必须同时在table2 table3中都有
CREATE TRIGGER T_insert_table1 ON table1
FOR INSERT
AS
if not exists (select * from
(select 1 b from table2 a join inserted b on a.编号=b.编号 and a.卡号=b.卡号
union
select 1 b from table3 c join inserted b on c.编号=b.编号 and c.卡号=b.卡号) a)
begin
print 'error'
rollback tran
end