Solved

Copy table structure only from one db to another

Posted on 2013-06-24
5
261 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
Comment Utility
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
Comment Utility
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
Comment Utility
I am using SQL 2008. I just want to copy the structure of the tablet
0
 
LVL 4

Expert Comment

by:MrC63
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with SQL Query 23 39
Distinct values from two tables 14 16
t-sql splitting string column 5 24
SQL Transaction logs 8 6
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
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…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

10 Experts available now in Live!

Get 1:1 Help Now