Shadow Copy in SQL 2008 without using create command
In this article, you will see how to create a duplicate table with a new name in SQL Server.
Introduction
In this article I will show you the various methods of copying a table with a new name using a select statement in SQL Server. It takes a lots of time to create new empty table and defining all field names again. Various methods are explained below.
Creating Table in SQL Server
create table StudentDetails
(
roll_num int,
F_Name varchar(15),
L_Name varchar(15),
City varchar(15)
)
|
Insert values in above table and table will look like below image
Technique I
Select all columns into new table but this way of copying will not copy constraints and indexes. This technique will copy all the columns of the source table (StudentDetails) to the destination table (StudentDetailsCopy).
Technique II
Select only the columns we want into the new table. Suppose we want to copy roll_num, F_Name, City columns from StudentDetails table into the StudentDetailsCopy1 table.
Technique III
To copy the structure of the source table into another new table with new name.
Here, 1=2 will prevent the data from being copied from StudentDetail to the StudentDetailCopy2 table.