当前位置: 代码迷 >> Sql Server >> Mysql使用存储过程,剔除表数据
  详细解决方案

Mysql使用存储过程,剔除表数据

热度:72   发布时间:2016-04-24 09:28:25.0
Mysql使用存储过程,删除表数据
我现在有两张表A,B,两张表有外键关联,现在我想使用mysql的存储结构删除A表(关联B表)的数据,怎么写啊
------解决思路----------------------
除了使用级联删除外,还可以使用临时表删除:

Select * 
into #tmpAB
from A AS a
 JOIN B as b on a.id=b.id;

Delete from A 
where exists(select 1 from #tmpAB where #tmpAB.id=A.id);
Delete from B
where exists(select 1 from #tmpAB where #tmpAB.id=B.id);
  相关解决方案