Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy table structure only from one db to another

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 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