Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Truncate source table after copy sql 2005

Posted on 2009-04-08
10
Medium Priority
?
403 Views
Last Modified: 2012-05-06
Hello,
I see all of the advice on how to copy the tables from one db to another...
Here is my situation:
I need to copy (once daily) data from Server1 DB1 Table to Server 2 DB2 Table... Structure is exact (Primary Key is exact). Both are SQL 2005
THEN Truncate the data in DB1 Table.

So, if this is my SP (below) to copy (is it correct?) then I need to know:
How to set it up to run daily
How to Truncate data in DB1 Table.
SELECT * INTO DB2.dbo.Table FROM DB1.dbo.Table (I'll use field names if that is recommeded - cleaner)
0
Comment
Question by:ncrocker
  • 6
  • 3
10 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 24098285
If you're transferring to a different server and don't have a linked server setup, you'll want to use SSIS to do the transfer.  From there, you can create a sql agent job to run the package, and after that step, run a truncate table statement:

truncate table tablename

Does that make sense? you just need a sql agent job to run whatever you need...that way you can schedule it to run daily.
0
 

Author Comment

by:ncrocker
ID: 24098386
Ok, Consider me stupid... How do I know If I have a linked server... I think I do...
I was given a little direction on this and was told that I should:
Get data from DB1 Table Copy into DB2 Table, then truncate... I'm sure I need to (delete) truncate the data on DB1 as it is our live server that doesn't really need this data after the copy.
Where would my truncate table statement live?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24098412
Can you currently transfer data from your source server to your destination server ok?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:ncrocker
ID: 24098460
Yes
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 80 total points
ID: 24098486
OK, no problem then.  Just use whatever code you have from your first post.  Now you need to create a SQL Job.  Here's an article I wrote that shows how:
http://blogs.techrepublic.com.com/datacenter/?p=296
0
 

Accepted Solution

by:
ncrocker earned 0 total points
ID: 24098576
So,
My SP would look like this:
IF OBJECT_ID('DB1') IS NULL
  BEGIN
      SELECT * INTO DB2.Table
      FROM DB1.Table            

      ALTER TABLE DB1

  END        

 TRUNCATE TABLE DB1.Table  
And Then I'd just schedule the sp?
0
 

Author Comment

by:ncrocker
ID: 24208360
This has not worked.
0
 

Author Comment

by:ncrocker
ID: 24743870
Only part of chapmandew's solution worked; I was able to get the rest to work myself.
0
 

Author Comment

by:ncrocker
ID: 24743874
All points to chapmandew:
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24744492
"as the solution and chapmandew's comment #24098486 (20 points)"
20 points?  That was very generous of you.  Are you sure you can spare those points?
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

916 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