how to copy table structure from one Database to another database

Posted on 2012-08-23
Last Modified: 2012-08-23
How to copy tables structure from one Database and paste to another database

i am newbie for SQL Server 2008 R2
Question by:crystal_Tech
    LVL 13

    Assisted Solution

    The easiest way is using 'select into':

    select * into otherdb..newtable from currenttable where 1=2
    LVL 18

    Assisted Solution

    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]

    These lines should be removed before to run the script in the new database
    LVL 1

    Author Comment

    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
    LVL 15

    Accepted Solution

    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.
    LVL 1

    Author Comment

    Thanks for quick answer. :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    779 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