Solved

Insert into sql table by batches

Posted on 2011-02-28
5
494 Views
Last Modified: 2012-05-11
Hi,
Can someone give me some idea how to perform batch insert in sql2005 by using t-sql ? My query below doesnt run in batch if I try with "top" ? will that work ? the date_time below contain aroun 30 millions of records, that is why I plan to run the insert per 100000 batches

      INSERT into  DBTestA.dbo.LoggingA
      SELECT *
      FROM DBProdA.dbo.LoggingA with (nolock)  where date_time>'2010-12-01 23:59:59.999'
 
     and date_time>'2010-12-31 23:59:59.999'

   
0
Comment
Question by:motioneye
5 Comments
 
LVL 15

Assisted Solution

by:derekkromm
derekkromm earned 150 total points
Comment Utility
You may want to look at SSIS to handle this type of functionality.

As a side-note, if you're trying to insert just Dec 2010, the last line should be <= rather than >
0
 

Author Comment

by:motioneye
Comment Utility
How about if I use bcp ? will that help ?
0
 
LVL 15

Expert Comment

by:derekkromm
Comment Utility
It may, but I won't be much help there as I don't have any experience with it.
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
is there a unique key there?  if you order by key, then you can select the top 10000 with a key greater than the greatest key in the DBTestA.dbo.LoggingA table
0
 
LVL 10

Accepted Solution

by:
John Claes earned 350 total points
Comment Utility
using the UniqueKey as my UniqueKey I would suggest the folowing


INSERT into  DBTestA.dbo.LoggingA
      SELECT top 100000 *
      FROM DBProdA.dbo.LoggingA
     with (nolock)  
     where date_time>'2010-12-01 23:59:59.999'
     and date_time>'2010-12-31 23:59:59.999'
     and UniqueKey not in (select UniqueKey from  DBTestA.dbo.LoggingA )

Every Run You insert a Batch of 100000 Records That are not already in the Logging Tabel

regards

Poor Beggar

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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…

743 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

15 Experts available now in Live!

Get 1:1 Help Now