Copy tables and stored procedures from one SQL db to another

Posted on 2009-12-21
Last Modified: 2012-05-08
What is the easiest way to copy "ALL" tables (with constraints, triggers and validations) and stored procedures from one DB to another.

My original db is called dbRec and Im trying to move them to another called dbPanel.

Im not sure how to write this syntax and if it is doable.

Question by:AIdoHSG
    LVL 75

    Accepted Solution

    you can create a backup and restore it as a new database
    LVL 3

    Expert Comment

    IF trying to copy tables/store procedures from one db to another db on the same server
    1.) right click on the destination DB and click on All Tasks> Import Data
    2.) click on Next,
    3.) choose the source DB
    4.) enter the credentials
    5.) choose the object you want to move / copy

    this is the simplest
    LVL 3

    Assisted Solution

    another simple way
    1.) select all the tables/stored procedure from source DB
    2.) right click on the selection and then click on All Tasks>generate sql
    3.) copy the SQL statements and paste it on sql query analyser with respect to your destination db
    4.) run all the queries which in turn will recreate the structure of the tables and stored procedure

    good luck

    Author Closing Comment

    That worked... thank you...
    the import wizard didn't bring my data or kept the table structures (i.e. constraints, indexes and validations)

    I still needed to do a back up in order to retrieve my data.
    LVL 3

    Expert Comment

    the import data transfers data too.
    in the wizard the last dialog screen has an option called ***** copy data.
    you have to select that

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    In this article I will describe the Backup & Restore 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.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

    737 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

    23 Experts available now in Live!

    Get 1:1 Help Now