Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Copying a tables contents in it's entirety

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-10-14 : 13:55:31
i know this is probably simpler than i'm making it, but.....

I have some data in a table that i need to do some major butchering on. In order to preserve that data as best i can, i created an identical table (same keys, same constraints, same columns) and gave it a new name in the same db. How do i copy the data from the 1st table (MNI_ADD) to the new one (MNI_ADD-TEST). Then, once i've done what i need to do in that table, how do i copy that data back over to the 1st table (MNI_ADD)?

thanks

james

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-14 : 13:59:29
for copying back, use UPDATE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-10-14 : 14:07:23
Ok. and i figured out how to make a query to pull the data out of table1 and create insert statements. I scripted it out as an "insert" query and ran that against the new table.

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-14 : 14:14:59
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-10-15 : 05:51:36
You can use merge statement. It will definitely work for you.

First copy data from 1st to second table then after perform you operation on 2nd table, then use merge statement to perform update,insert,delete on first table.

Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh
Go to Top of Page
   

- Advertisement -