Truncate source table after copy sql 2005

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)
ncrockerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ncrockerConnect With a Mentor Author Commented:
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
 
chapmandewCommented:
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
 
ncrockerAuthor Commented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
chapmandewCommented:
Can you currently transfer data from your source server to your destination server ok?
0
 
ncrockerAuthor Commented:
Yes
0
 
chapmandewConnect With a Mentor Commented:
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
 
ncrockerAuthor Commented:
This has not worked.
0
 
ncrockerAuthor Commented:
Only part of chapmandew's solution worked; I was able to get the rest to work myself.
0
 
ncrockerAuthor Commented:
All points to chapmandew:
0
 
Anthony PerkinsCommented:
"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
All Courses

From novice to tech pro — start learning today.