Solved

Query to insert and select by batches

Posted on 2014-02-27
3
439 Views
Last Modified: 2014-02-27
I have write the query below, but I have a doubt that will this query run with inserting only new records by batches or  will it run endlessly.

DECLARE @i INT
WHILE 1 = 1 BEGIN
     BEGIN TRANSACTION
      Insert into SynState select  TOP(10000) * --into SyncExchangeStateData
      FROM SyncSatteTrue with (nolock)

      SET @i = @@ROWCOUNT
      commit transaction
      IF @i = 0 BREAK
     
END
GO
0
Comment
Question by:motioneye
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39891479
it will run endlessly, as you don't specify anywhere which rows to "skip" on next run, and you don't delete any rows neither...
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 39891504
As Guy Hengel stated, it will run endlessly, if you want to do  it in batches, have a look at:

http://sqlserverplanet.com/data-warehouse/transferring-large-amounts-of-data-using-batch-inserts
(Transferring Large Amounts of Data using Batch Inserts)
0
 

Author Closing Comment

by:motioneye
ID: 39891510
Thanks, Now I fix the script :)
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now