SQL中如何同时删除两个表中ID相同的记录?

来源:百度知道 编辑:UC知道 时间:2024/07/02 16:49:47
比如同时删除A,B表中a.id=b.id的所有记录?a.id=9,谢谢。

insert a.id into #kkk select a.id from a,b where a.id=b.id
delete from a where a.id in(select id from #kkk)
delete from b where b.id in(select id from #kkk)

-------------------------
第一句得到两个表里的相同记录并插入临时表
第二句把A表里的记录删除,条件是#kkk表里的ID
第三句把B表里的记录删除,条件是#kkk表里的ID

delete from a where a.id =9
delete from b where b.id =9

想一句Sql删除2个表中的数据不可能