Copy all objects (tables, views, functions, stored procedures) from one DB to another DB

  • I need to copy some selected objects (tables, views, functions, stored procedures) from one DB (Order) to another DB (OrderHistory)
    Which way can do this job?
    Import and export only can do tables.

  • In Management Studio right click on your database then Tasks --> Generate Scripts. Post back if you have any problems.

    Thanks

  • adonetok - Friday, August 10, 2018 1:31 PM

    I need to copy some selected objects (tables, views, functions, stored procedures) from one DB (Order) to another DB (OrderHistory)
    Which way can do this job?
    Import and export only can do tables.

    Why not simply restore the Order database as OrderHistory?
    😎

  • I'll also add that if you had proper source control running, this would be a cake walk. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • adonetok - Friday, August 10, 2018 1:31 PM

    I need to copy some selected objects (tables, views, functions, stored procedures) from one DB (Order) to another DB (OrderHistory)
    Which way can do this job?
    Import and export only can do tables.

    You can also create Linked server in SQL server management studio to have connection between two server which can be later exploited for your requirement.

    Reference Link :
    https://www.sqlshack.com/how-to-create-and-configure-a-linked-server-in-sql-server-management-studio/

  • Someone told me that bcp will do it.
    I'll learn it.

  • adonetok - Monday, August 20, 2018 5:18 AM

    Someone told me that bcp will do it.
    I'll learn it.

    The Bulk Copy Program can help you with the data but not with the schemas and the objects.
    😎

  • Is there any reason you're not able to use the other solutions that have been posted? They are pretty simple to implement.

    Thanks

  • adonetok - Monday, August 20, 2018 5:18 AM

    Someone told me that bcp will do it.
    I'll learn it.

    Eirikur is correct and you're not listening to the correct people. 😉 You COULD use BCP to export sys.SQL_Modules but that will only cover type P, RF, V, TR, FN, IF, TF, and R objects in the server.  It will not handle table definitions and it misses several other worlds.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply