Nothing loose by learning again. Definitely gain If you just don't let it go away. - Bvsc.
Friday, November 23, 2012
Table Backup with native SQL, Process 4
-- Table Backup with native SQL, Process 4
Version : SQL 2008 or later.
Table Backup.
You can get the result in 4 types...
Process 1 : Generating scripts
Process 2 : Import/Export Option (T-SQL/SSIS)
Process 3 : Inserting into new table (Select * into newtab from baktab)
Process 4 : Inserting into existing table (Create newtable with same structure as
Original table, Insert into newtable select * from backtab)
Here we can see Process 4 : We discussed other 3 ways in earlier posts..Process1, Process2 and Process3
So two steps first copy the skeleton/Structure/schema of the table and in next step load that table.
Step 1:
SELECT * FROM OriginalTab_Backup FROM OriginalTab where 1 = 2
You can use any type of comparison in where condition, those should not equal.
It will just print the structure of the 'OriginalTab' table in 'OriginalTab_Backup'.
Step 2:
Now we have to load the table, We can use few other ways to do so. But I am using the below.
INSERT INTO OriginalTab_Backup SELECT * FROM OriginalTab
You can also use Bulk Insert to load the table, which is most used one. I will post this in future.
By using this process, You can take the backup of full table or selected columns.
like below..
SELECT Col1,Col2,Col3 FROM OriginalTab_Backup FROM OriginalTab where 1 = 2
INSERT INTO OriginalTab_Backup SELECT Col1,Col2,Col3 FROM OriginalTab.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment