Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 copy data from one table to another with constrain

Author  Topic 

amurark
Yak Posting Veteran

55 Posts

Posted - 2012-12-26 : 10:10:02
hi all
Pls tell me how to copy one table from another with its constrints structure

I tried
Select * into table2 from table1

but it don't copy constraints , indexes, triggers etc.

Pls tell me how to do it

Ankita

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-12-26 : 11:37:40
You can't do that, SELECT INTO only copies structure and data types. To get everything, it'd be better to create the table first, anyway. You can go in to Object Explorer, right-click on table1, then choose SCRIPT TABLE AS ---> Create.
Then just change then name to table2 before you run the script. You may need to go in to tools\options\ SQL Server Object Explorer\ Scripting to make sure that all the objects you want get scripted.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-26 : 23:03:16
quote:
Originally posted by amurark

hi all
Pls tell me how to copy one table from another with its constrints structure

I tried
Select * into table2 from table1

but it don't copy constraints , indexes, triggers etc.

Pls tell me how to do it

Ankita



generate scripts using wizard accessed from tasks-> generate scripts and you can select what all properties you want to script out.


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -