Tuesday, June 18, 2013

Copy a table into new table with/without data - SQL Server

 how to copy an existing table to new table in SQL Server. There are two options. They are
  • Copy only the structure of an existing table into new table
  • Copy only the structure with data of an existing table into new table
Copy only the structure of an existing table into new table:

SELECT * INTO tableNew FROM tableOld WHERE 1=2

The above query will copy the structure of  an existing table(tableOld) into the new table(tableNew).

Copy only the structure with data of an existing table into new table:

SELECT * INTO tableNew FROM tableOld