Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Commit Question

Status
Not open for further replies.

Jimreaper

MIS
May 22, 2001
21
US
Hello all,
What is the proper SQL to use for this senario:
Insert all records into table1 from table2 and commit after every 10000 rows until complete.

Thanks for helping a beginner.
Jim
 
Assuming the table has an identity column or unique constraint, you could do something like the following.

Set Rowcount 10000

Declare @rc int
Select @rc=1

While @rc>0
Begin
Begin Transaction
Insert table2 (ID, Col2, col3, ....)
Select ID, colB, colC, ...
From table1
Where Not Exists
(Select * From table2
Where ID=table1.ID)
Select @rc=@rowcount
Commit
End

Set rowcount 0 Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top