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

Lets see 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  NewTable  FROM OldTable WHERE 3=4
The above query will copy the structure of  an existing table(OldTable ) into the new table(NewTable).

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

SELECT * INTO NewTable  FROM OldTable

This is also same like the previous query, but it copies the structure of existing table(OldTable) with data as well into the new table(NewTable)


When we write  SELECT 3 + NULL
The output is null

When we write SELECT * FROM TableName WHERE 1=1

It will display entire table data

Comments