delete where id in list

不打扰是莪最后的温柔 提交于 2019-12-29 11:40:13

问题


if i have a list of Ids (1, 4,6,7) and a db table that i want to delete all records where id is in this list, what is the fastest way of doing this?


回答1:


Your question almost spells the SQL for this:

DELETE FROM table WHERE id IN (1, 4, 6, 7)



回答2:


delete from t
where id in (1, 4, 6, 7)



回答3:


The correct answer is that speed depends on the characteristics of the particular implementation/engine that you are using, and that you should beware of any quack who pretends to be able to give a definite answer to this question.

If the optimizer of your system is so poor that it does not spot the optimization opportunity from 'WHERE id IN (...)', then it will do a table scan, which might be a lot slower than giving 4 separate delete commands.



来源:https://stackoverflow.com/questions/2615566/delete-where-id-in-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!