?
Solved

Query to insert and select by batches

Posted on 2014-02-27
3
Medium Priority
?
448 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

764 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