Solved

Query to insert and select by batches

Posted on 2014-02-27
3
440 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
need help in sql 4 66
MS SQL Inner Join - Multiple Join Parameters 2 19
Ssis not sending failure message 2 9
C# guarantee sql connection close 6 25
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

911 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

20 Experts available now in Live!

Get 1:1 Help Now