当前位置: 代码迷 >> Sql Server >> 求教 主从表 数据剔除
  详细解决方案

求教 主从表 数据剔除

热度:1   发布时间:2016-04-27 11:30:10.0
求教 主从表 数据删除
现有表 A(主表 字段ID),B(从表ID,A_ID)两张表,现在要删除从表中不被主表关联到的数据。
不要下面的这种方法
delete from B where B.ID not in( select B.ID from A join B on A.ID = B.A_ID )

------解决方案--------------------
SQL code
delete B where not exists (select 1 from A where A.ID=B.ID)
  相关解决方案