删除sql server中的大量数据 [英] Delete large amount of data in sql server

查看:65
本文介绍了删除sql server中的大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含 10000000 条记录的表.这两种解决方案有什么区别?

Suppose that I have a table with 10000000 record. What is difference between this two solution?

  1. 删除如下数据:

  1. delete data like :

DELETE FROM MyTable

  • 逐行删除应用程序的所有数据:

  • delete all of data with a application row by row :

    DELETE FROM MyTable WHERE ID = @SelectedID
    

  • 第一个解决方案是否具有最佳性能?对日志和性能有什么影响?

    Is the first solution has best performance? what is the impact on log and performance?

    推荐答案

    如果你的表中有那么多记录并且你想把它们全部删除,你应该考虑 truncate

    中删除.它会更快,但请注意它无法激活触发器.

    If you have that many records in your table and you want to delete them all, you should consider truncate <table> instead of delete from <table>. It will be much faster, but be aware that it cannot activate a trigger.

    查看更多详细信息(本例为 sql server 2000):http://msdn.microsoft.com/en-us/library/aa260621%28SQL.80%29.aspx

    See for more details (this case sql server 2000): http://msdn.microsoft.com/en-us/library/aa260621%28SQL.80%29.aspx

    删除应用程序中的表逐行将在很长一段时间内结束,因为您的dbms无法优化任何东西,因为它事先不知道您将要删除一切.

    Deleting the table within the application row by row will end up in long long time, as your dbms can not optimize anything, as it doesn't know in advance, that you are going to delete everything.

    这篇关于删除sql server中的大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆