我有一个MySQL数据库,我需要删除表father
的一些内容,但有些FK在我的表father
和表child
之间有限制,为此,我必须从child
表中删除,然后从father
表中删除。
我有:
DELETE FROM child WHERE child.id IN (SELECT id FROM father);
我想知道,如果我使用
,它会有性能变化(除了额外的选择)DELETE FROM child WHERE child.id IN (1,2,...,n)
其中1,2 ... n与'SELECT id FROM father'的结果相同。
答案 0 :(得分:0)
比使用多表DELETE更快:
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
cardView.setContentPadding(-padding,-padding,-padding,-padding);
不应该是DELETE FROM child
USING father JOIN child
ON child.id = father.id;
??不,即使这似乎错了吗?
这似乎更接近你的英语:
child.father_id
DELETE FROM child
USING father JOIN child
ON child.father_id = father.id -- more likely FK
WHERE father...; -- picking the Dads in question
DELETE FROM father
WHERE father...; -- picking the Dads in question
可能会稍快一些。