当前位置: 代码迷 >> Sql Server >> 跨表删除的有关问题,大伙进来看看
  详细解决方案

跨表删除的有关问题,大伙进来看看

热度:34   发布时间:2016-04-27 16:17:34.0
跨表删除的问题,大伙进来看看~
如果对比2表,查询表B,如果在表A中不存在的,删除表B中的行

表A:
id       hy           isok
1         001             1
2         002             1

……

表B:

id       hy          
1         001            
2         002  
3         003    
       
……

如表所示,运行后应该删除   表B   中的   第3行


------解决方案--------------------
delete B
where checksum(id,hy) not in (select checksum(id,hy) from A)
------解决方案--------------------
delete from B where not exists(select 1 from A where A.id=B.id and A.hy=B.hy)
  相关解决方案