Friday 25 March 2016

SQL SERVER -- Table BackUp-- Part-14

SQL SERVER -- Table BackUp-- Part-14

Description:-
                                               When we working with Production Data Base Tables always good practice to take Table backup and do the manipulations.
If any things goes wrong then we can re-populate the data from backup table to actual tables.

How to Take Table Backup along with Data :- 
SELECT *
INTO EMP_20160325_BKP  /* New Table Name */
FROM EMP              /* Actual(Old) Table Name */
WHERE 1=1

-- Verify
SELECT * FROM EMP_20160325_BKP




How to Take Table Backup without Data, Only Table Structure :- 
SELECT *
INTO EMP_TBL_STRUCT /* New Table Name */
FROM EMP            /* Actual(Old) Table Name */
WHERE 1=2

-- Verify
SELECT * FROM EMP_TBL_STRUCT




How to Insert data from one Table to Another table :- 
INSERT INTO EMP_TBL_STRUCT
SELECT * FROM EMP

-- Verify
SELECT * FROM EMP_TBL_STRUCT





No comments:

Post a Comment