Create Clone of Existing Table using script in SQL Server 2008
In this article, you will see how to create a duplicate table with a new name in SQL Server.using script.
In this article I will show you the various methods of copying a table with a new name using a script in SQL Server. It takes a lots of time to create new empty table and defining all field names again.
Creating Table in SQL Server
create table StudentDetails
Insert values in above table and table will look like below image.
Copying table using general select into query ignores the indexes and constraints. So generate the script of the table.
Generate Table Script in SQL Server Management Studio
- Open Object Explorer . And right click on table whose script is to be created. Suppose you want to generate script for table called Student. Select Script Table as -> CREATE TO -> New Query Editor Window.
- Script is generated for the table called StudentDetails in a new query window.
- Now use this script after changing the name of table in the script which you want the new table to be named.
- Execute above script.
- Now refresh the database in which you create the table. Now you can see, the new table is created in deep database.