al4629740
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?
How can I do this in SQL?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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