Solved

Insert into sql table by batches

Posted on 2011-02-28
5
508 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
ID: 34997546
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
ID: 34997607
How about if I use bcp ? will that help ?
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 34997628
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
ID: 34997682
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
ID: 34997765
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

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

867 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

21 Experts available now in Live!

Get 1:1 Help Now