Solved

Query to insert and select by batches

Posted on 2014-02-27
3
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

724 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