table2 结构如id int,pid int
CREATE TRIGGER [P] ON [dbo].[Table2]
FOR DELETE
AS
declare @key int;
select @key=id from deleted
delete table2 where pid=@key
CREATE TRIGGER [P] ON [dbo].[Table2]
FOR DELETE
AS
declare @key int;
select @key=id from deleted
delete table2 where pid=@key
while exists (select id from table1 where id not in (select * from #temp)
and pid in (select * from #temp))
insert into #temp
select id from table1 where PID in (select * from #temp)
and id not in (select * from #temp)
select * from #temp
delete from table1 where id in (select * from #temp)