Solved

Copy table structure only from one db to another

Posted on 2013-06-24
5
262 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
  • 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 65

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 65

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Copy Database Wizard 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.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now