关于参照完整性规则的MySQL删除表

时间:2015-12-04 09:07:46

标签: mysql database integrity referential

我要删除Intent intent = new Intent(this, NextActivity.class); startActivity(intent); ,同时移除tableA中匹配tableB

的所有行

目前,tableA.A_ID = tableB.A_ID的{​​{1}}上的删除和更新设置为CASCADE的外键设置为TableB

1 个答案:

答案 0 :(得分:1)

暂时关闭约束

SET SQL_SAFE_UPDATES = 0;

DELETE FROM tableB b WHERE EXISTS ( SELECT * FROM tableA a WHERE a.A_ID = b.A_ID )

DELETE FROM tableA;

SET SQL_SAFE_UPDATES = 1;