日期:2014-05-17 浏览次数:20503 次
create table b(b1 int primary key)
insert into b
select 1 union all
select 2
create table c(c1 int primary key)
insert into c
select 1 union all
select 2
create table a(
b1 int foreign key references b(b1),
c1 int foreign key references c(c1)
)
insert into a
select 1,1 union all
select 1,2 union all
select 2,1
go
create trigger dbo.trigger_b_delete
on dbo.b
for delete
as
delete b
from deleted d
where b.b1 = d.b1
go
create trigger dbo.trigger_c_delete
on dbo.c
for delete
as
delete c
from deleted d
where c.c1 = d.c1
go
delete from b where b1 = 1
--自动删除了b1 = 1的记录
select * from a
/*
b1 c1
2 1
*/
delete from c where c1 = 1
--自动删除了c1 = 1的记录
select * from a
/*
*/