Solved

Insert into sql table by batches

Posted on 2011-02-28
5
538 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 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

751 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