• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1021
  • Last Modified:

how to copy table structure from one Database to another database

How to copy tables structure from one Database and paste to another database

i am newbie for SQL Server 2008 R2
0
crystal_Tech
Asked:
crystal_Tech
3 Solutions
 
alpmoonCommented:
The easiest way is using 'select into':

select * into otherdb..newtable from currenttable where 1=2
0
 
vastoCommented:
If you wan to copy just the structure then in Management Studio right click on the table  and select "Script Table As" ->"Create To"->"New Query Editor Window".  This will create a script which you can run in the other database and create the table. The script will start with

USE [CurrentDatabaseName]
GO

These lines should be removed before to run the script in the new database
0
 
crystal_TechAuthor Commented:
SQL Server Management Studio's "Import Data" task (right-click on the DB name, then tasks) will do most of this for you. Run it from the database you want to copy the data into.

If the tables don't exist it will create them for you, but you'll probably have to recreate any indexes and such. If the tables do exist, it will append the new data by default but you can adjust that (edit mappings) so it will delete all existing data.

above solution is working for me.. thanks
0
 
AnujCommented:
I would say to go for generate script task, Right click the source database, Select Tasks -> generate script wizard, This wizard will guide you to script the objects in a database. You can query all the objects in a database, or selected objects. The script can be saved in a New Query window, or file or in a clip board.
0
 
crystal_TechAuthor Commented:
Thanks for quick answer. :-)
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now