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
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Table backup

Author  Topic 

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2008-01-14 : 16:04:38
I have a large table that I need to play with a devise a solution. I want to make a back up copy of it so that if I crash it I can easily restore. What is the best way to backup/restore a single table?

mauler05
Starting Member

17 Posts

Posted - 2008-01-14 : 17:08:57
The easiest way is to execute following

Select * into TempTable from YourOriginaltable

and then if something goes wrong to YourOriginaltable then you can copy back everything from TempTable to YourOriginaltable by following :

ALTER TABLE YourOriginaltable NOCHECK CONSTRAINT ALL
--Temporarily disable constraint on YourOriginaltable

delete from YourOriginaltable
--make sure you are not duplicating

Insert into YourOriginaltable
Select * from TempTable
--YourOriginaltable will be back in the same state

ALTER TABLE YourOriginaltable CHECK CONSTRAINT ALL
--Place constraint back on YourOriginaltable

Go to Top of Page

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2008-01-14 : 17:30:26
Good plan. :) Thank you
Go to Top of Page
   

- Advertisement -