简体   繁体   English

更新/插入后阻止提交处理1000万条记录的提交

[英]Block commit after Update/Insert for 10 million records being processed

Requirements need an Update and Insert for 10 million records in Sql Server 2005. I have created a Stored Procedure using T-SQL. 需求需要在Sql Server 2005中进行1000万条记录的更新和插入。我已经使用T-SQL创建了存储过程。 Do we need to do a commit after the process above , say 10000 records committed at at time. 我们需要在上述过程之后进行一次提交吗,比如说一次提交了10000条记录。 If so how do I write a commit statement for say every 10000 records. 如果是这样,我该如何写每10000条记录的提交语句。 Any ideas would be appreciated. 任何想法,将不胜感激。

In general, a way to do batch deletes/updates/inserts is to use a WHILE loop. 通常,批量删除/更新/插入的一种方法是使用WHILE循环。 The pattern I normally follow is: 我通常遵循的模式是:

WHILE 1=1
BEGIN
 INSERT INTO dbo.MyTable
 (field1, field2, field3...)
 SELECT TOP 100000 (field1, field2, field3...)
 FROM dbo.MySourceTableorQuery as S
 WHERE NOT EXISTS (
        SELECT * FROM dbo.SourceTableorQuery as S 
        WHERE s.PrimaryKey = MyTable.PrimaryKey)
 IF @@ROWCOUNT<100000 BREAK;
END

As to "whether you need to", that's impossible to answer without a lot of other information. 至于“是否需要”,没有很多其他信息就不可能回答。 What kind of query is it, what's the table structure like, how long does it take to run currently, how are you for disk space (you will really increase the size of tempdb if it's a single transaction), how wide is the table you are inserting to, etc? 它是一种什么样的查询,它的表结构是什么样的,当前运行需要多长时间,磁盘空间如何(如果是单个事务,您确实会增加tempdb的大小),表的宽度是多少正在插入等?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM