下面这个只能删除一个表中满足条件的记录。
delete a
from a,b
where a.ID=b.ID
5 个解决方案
#1
delete a where ID in (select ID from b)
delete b where ID in (select ID from a)
delete b where ID in (select ID from a)
#2
delete a where ID in (select ID from b)
delete b where ID not in (select ID from a)
delete b where ID not in (select ID from a)
#3
select * into #temp from a
delete a where id in(select id from b)
delete b where id in(sleect id from #temp)
delete a where id in(select id from b)
delete b where id in(sleect id from #temp)
#4
一次操作不能同时删除两个表的数据
除非你用触发器
create trigger tr_name table1
for delete
as
delete table2 where id in (select id from deleted)
然后删除
delete table1 where id条件
除非你用触发器
create trigger tr_name table1
for delete
as
delete table2 where id in (select id from deleted)
然后删除
delete table1 where id条件
#5
不能同时删除
用触发器,或者用临时表来保存一个表的记录
用触发器,或者用临时表来保存一个表的记录
#1
delete a where ID in (select ID from b)
delete b where ID in (select ID from a)
delete b where ID in (select ID from a)
#2
delete a where ID in (select ID from b)
delete b where ID not in (select ID from a)
delete b where ID not in (select ID from a)
#3
select * into #temp from a
delete a where id in(select id from b)
delete b where id in(sleect id from #temp)
delete a where id in(select id from b)
delete b where id in(sleect id from #temp)
#4
一次操作不能同时删除两个表的数据
除非你用触发器
create trigger tr_name table1
for delete
as
delete table2 where id in (select id from deleted)
然后删除
delete table1 where id条件
除非你用触发器
create trigger tr_name table1
for delete
as
delete table2 where id in (select id from deleted)
然后删除
delete table1 where id条件
#5
不能同时删除
用触发器,或者用临时表来保存一个表的记录
用触发器,或者用临时表来保存一个表的记录