Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create duplicate table with new name in SQL Server 2008

How do I create a duplicate table with only the structure duplicated with a new name in SQL server 2008?

I have table with 45 fields so I want to create new with same structure but new name.

like image 720
Eyla Avatar asked Jul 13 '10 21:07

Eyla


People also ask

How do you replicate a table in SQL?

If you want to copy the data of one SQL table into another SQL table in the same SQL server, then it is possible by using the SELECT INTO statement in SQL. The SELECT INTO statement in Structured Query Language copies the content from one existing table into the new table.

How do you create a new table from an existing table in SQL?

You can also use the SQL CREATE TABLE AS statement to create a table from an existing table by copying the existing table's columns. It is important to note that when creating a table in this way, the new table will be populated with the records from the existing table (based on the SELECT Statement).


2 Answers

Right click on the table in SQL Management Studio.

Select Script... Create to... New Query Window.

This will generate a script to recreate the table in a new query window.

Change the name of the table in the script to whatever you want the new table to be named.

Execute the script.

like image 138
Avalanchis Avatar answered Oct 14 '22 11:10

Avalanchis


SELECT * 
INTO target
FROM  source
WHERE 1 = 2
like image 52
Conrad Frix Avatar answered Oct 14 '22 11:10

Conrad Frix