1

我想删除tableA,同时删除所有tableB匹配的行tableA.A_ID = tableB.A_ID

目前我有一个外键设置为CASCADE删除和更新设置TableBtableB.A_ID.

4

1 回答 1

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;
于 2015-12-04T09:11:37.620 回答