Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想删除tableA,同时删除所有tableB匹配的行tableA.A_ID = tableB.A_ID
tableA
tableB
tableA.A_ID = tableB.A_ID
目前我有一个外键设置为CASCADE删除和更新设置TableB为tableB.A_ID.
CASCADE
TableB
tableB.A_ID
通过以下方式暂时关闭约束
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;