Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

Copy table structure only from one db to another

I have a table1 in database1.  I would like to copy table1 to database2 and name it table1 again.

How can I do this in SQL?
Avatar of MrC63
MrC63
Flag of Canada image

Which version of SQL are you using -- and are you attempting to copy the entire table complete with contents, or just the structure?
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of al4629740

ASKER

I am using SQL 2008. I just want to copy the structure of the tablet
jimHorn presented the exact option I was going to suggest, and since you're using SQL 2008 it will work perfectly.

The trick is that, depending on which specific version of SQL 2008 you're using (Express, Standard, Enterprise) you may or may not see the "USE [DBName] at the top of the script.  If it's not there, simply add it.

You can also edit the script, before you execute it, to change the table name to your preferred name.

Once you have the "CREATE TO" script as shown in JimHorn's diagram, simply click on the red ! icon in your toolbar above.  This will execute the script, and will create an identical table in the alternate database.
Thanks for the grade.  Good luck with your project.  -Jim