WHERE IN 查询中可能的最大值
我有一个包含超过 3000000 个条目的表,我需要删除其中 500000 个具有给定 ID 的条目。 我的想法是创建一个如下查询:
DELETE FROM TableName WHERE ID IN (id1, id2, ...........)
我用简单的 C# 代码生成它。 问题是: 我可以在 ID 数组中设置的值数量是否有限制?
如果有人有更好的方法来更有效地实现此删除,我愿意接受想法。
I have a table with over 3000000 entries, and i need to delete 500000 of them with given ID's.
My idea is to create a query like:
DELETE FROM TableName WHERE ID IN (id1, id2, ...........)
which I generate with a simple C# code.
The question is:
is there a limit to how many values I can set in the array of ID's.
And if someone have a better way to achieve this delete more efficiently I'm open to ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的 ID 无法通过任何比较来确定(如
WHERE ID < 1000000
),您可以INSERT
插入具有多次插入的临时表中,然后将该临时表加入到您的临时表中
,但是插入可能会出现问题。你应该检查一下。你怎样才能加快这件事呢?
If your IDs can't be determined with whatever comparison (as in
WHERE ID < 1000000
) you couldINSERT
them into a temp table with multiple inserts and thenJOIN
this temp table to yoursBut inserts may become problematic. You should check that. How could you speed this thing up?
最后我的解决方案效果还不错:
1.对ID进行排序(以节省服务器分页)
2. 使用 C# 代码查询创建,其中包含 500 个 ID。
3.一一发送查询。
我假设当我处理具有 1000+ id 的查询时,sql server 处理查询的时间减慢了我的速度(毕竟您在 sql server 中运行的任何查询都正在处理和优化)。
我希望这对某人有帮助
At the end my solution which works not so bad:
1. Sorted the ID's (to save server paging)
2. Created with C# code query's with 500 ID's in them.
3. sent the query's one by one.
I assume that when i worked with query having 1000+ ids the sql server time to process the query was slowing me down (after all any query you run in sql server is being process and optimized).
I Hope this help someone