Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicating a TABLE using Microsoft SQL Server Management

Need to duplicate a TABLE using Microsoft SQL Management Studio 2008

The TABLE needs to duplicate all table row (Primary Key) ID as well.

like image 821
Alex Avatar asked Aug 30 '10 16:08

Alex


People also ask

How do I copy a table structure and data in SQL Server?

Right-click on the database name, then select "Tasks" > "Export data..." from the object explorer. The SQL Server Import/Export wizard opens; click on "Next". Provide authentication and select the source from which you want to copy the data; click "Next". Specify where to copy the data to; click on "Next".


1 Answers

In SSMS open a new query window and then do something like

SELECT * INTO NewTable FROM OldTable 

change NewTable to the name that the new table should have, change OldTable to the name of the current table

this will copy over the basic table structure and all the data...it will NOT do any of the constraints, you need to script those out and change the names in those scripts

like image 74
SQLMenace Avatar answered Oct 14 '22 14:10

SQLMenace