Solved

Truncate source table after copy sql 2005

Posted on 2009-04-08
10
389 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:ncrocker
ID: 24098460
Yes
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 20 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Abstract Express Replacement Software 12 28
Live Storage Vmotion VMs with shared VMDK 10 59
sql server computed columns 11 31
SQL Update trigger 5 18
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

777 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