Solved

Copy table structure only from one db to another

Posted on 2013-06-24
5
267 Views
Last Modified: 2013-06-25
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?
0
Comment
Question by:al4629740
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:MrC63
ID: 39272912
Which version of SQL are you using -- and are you attempting to copy the entire table complete with contents, or just the structure?
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39272930
Quickest way would be manually in SSMS to script out the CREATE TABLE (see below image) then in the resulting script change the USE [Original Database Name] line to USE [New Database Name], and execute it.

Create Table in SSMS
0
 

Author Comment

by:al4629740
ID: 39272996
I am using SQL 2008. I just want to copy the structure of the tablet
0
 
LVL 4

Expert Comment

by:MrC63
ID: 39273070
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.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39274592
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question