Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert into sql table by batches

Posted on 2011-02-28
5
Medium Priority
?
558 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
[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
5 Comments
 
LVL 15

Assisted Solution

by:derekkromm
derekkromm earned 600 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 1400 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

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.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
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…

661 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