How to copy a table to another with primary key?

6.8k views Asked by At

I am using this query:

SELECT * 
INTO table1 
FROM table2

To copy a table; it doesn't copy the primary key from table2 to table1 as Primary key. It just copies all columns - not constraints.

1

There are 1 answers

0
Ashokreddy On

As per my knowledge In SQL server it's not possible your requirement but in case you need same structure with primary key first generate script for existing table then create new table.

using ssms->object explorer->expand databases->select database->right click on table and generate script