Recreating existing Database Schema

  • Good day,

    I am wondering what would be the easiest way to recreate an existing database schema (sprocs, tables, constraints, etc..) without the data.

    In MSSQL, I know you can use the Generate Scripts in Task but this doesn't create a runnable script, you still need to order the execution manually since some tables might reference to other tables that aren't created yet.

    What's the best practice? (Knowing that this is a large database...)

    Regards,

    Shany Grimard

  • Best practice, be efficient. I know it sounds bad, but use a tool. This is a problem that doesn't lend itself to using your own time and effort to build as there is complexity here.

    The Generate scripts, if you build one script, should be runnable. Generate all objects and they should be ordered properly. If there a bugs in this process, I'd submit them to connect.microsoft.comhttp://connect.microsoft.com/.

    If you want more options, filtering, etc., a tool like SQL Comparehttps://www.red-gate.com/products/sql-development/sql-compare/ does this very well and is worth the cost in time savings.

    Disclosure: I work for Redgate.

  • You could try extracting a Dacpac and then deploying that.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Red-Gate +1

  • sgrimard (3/3/2016)


    Good day,

    I am wondering what would be the easiest way to recreate an existing database schema (sprocs, tables, constraints, etc..) without the data.

    In MSSQL, I know you can use the Generate Scripts in Task but this doesn't create a runnable script, you still need to order the execution manually since some tables might reference to other tables that aren't created yet.

    What's the best practice? (Knowing that this is a large database...)

    Regards,

    Shany Grimard

    if we are talking schema only/no data, the easier method is to generate the tables without the foreign key constraints, and generate the foreign keys separately. you can append them to the same file, but having all constraints added at the end solves the hierarchy order.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • If all you want is the structure, here's another vote for using the DACPAC. However, I'm with Steve (on multiple levels, I work with him), that if you need to do this regularly, the best way is with Redgate SQL Compare. It's all about the ability to automate and control what gets moved, when and how. If you're doing it a lot, we have the right tools for the job.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 6 posts - 1 through 5 (of 5 total)

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