Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy table structure only from one db to another

Posted on 2013-06-24
5
Medium Priority
?
269 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 66

Accepted Solution

by:
Jim Horn earned 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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.
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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