how to compare/validate sql schema

后端 未结 11 674
后悔当初
后悔当初 2021-02-02 16:02

I\'m looking for a way to validate the SQL schema on a production DB after updating an application version. If the application does not match the DB schema version, there should

相关标签:
11条回答
  • 2021-02-02 16:06

    Try this SQL.
    - Run it against each database.
    - Save the output to text files.
    - Diff the text files.

    /* get list of objects in the database */
    SELECT name, 
           type 
    FROM  sysobjects
    ORDER BY type, name
    
    /* get list of columns in each table / parameters for each stored procedure */
    SELECT so.name, 
           so.type, 
           sc.name, 
           sc.number, 
           sc.colid, 
           sc.status, 
           sc.type, 
           sc.length, 
           sc.usertype , 
           sc.scale 
    FROM   sysobjects  so , 
           syscolumns  sc 
    WHERE  so.id = sc.id 
    ORDER BY so.type, so.name, sc.name
    
    /* get definition of each stored procedure */
    SELECT so.name, 
           so.type, 
           sc.number, 
           sc.text 
    FROM   sysobjects  so , 
           syscomments sc 
    WHERE  so.id = sc.id 
    ORDER BY so.type, so.name, sc.number 
    
    0 讨论(0)
  • 2021-02-02 16:08

    You can do it programatically by looking in the data dictionary (sys.objects, sys.columns etc.) of both databases and comparing them. However, there are also tools like Redgate SQL Compare Pro that do this for you. I have specified this as a part of the tooling for QA on data warehouse systems on a few occasions now, including the one I am currently working on. On my current gig this was no problem at all, as the DBA's here were already using it.

    The basic methodology for using these tools is to maintain a reference script that builds the database and keep this in version control. Run the script into a scratch database and compare it with your target to see the differences. It will also generate patch scripts if you feel so inclined.

    As far as I know there's nothing free that does this unless you feel like writing your own. Redgate is cheap enough that it might as well be free. Even as a QA tool to prove that the production DB is not in the configuration it was meant to be it will save you its purchase price after one incident.

    0 讨论(0)
  • 2021-02-02 16:12

    Try dbForge Data Compare for SQL Server. It can compare and sync any databases, even very large ones. Quick, easy, always delivers a correct result. Try it on your database and comment upon the product.

    We can recommend you a reliable SQL comparison tool that offer 3 time’s faster comparison and synchronization of table data in your SQL Server databases. It's dbForge Data Compare for SQL Server.

    Main advantages:

    • Speedier comparison and synchronization of large databases
    • Support of native SQL Server backups
    • Custom mapping of tables, columns, and schemas
    • Multiple options to tune your comparison and synchronization
    • Generating comparison and synchronization reports

    Plus free 30-day trial and risk-free purchase with 30-day money back guarantee.

    0 讨论(0)
  • 2021-02-02 16:13

    If you are looking for a tool that can compare two databases and show you the difference Red Gate makes SQL Compare

    0 讨论(0)
  • 2021-02-02 16:18

    Which RDBMS is this, and how complex are the potential changes?

    Maybe this is just a matter of comparing row counts and index counts for each table -- if you have trigger and stored procedure versions to worry about also then you need something more industrial

    0 讨论(0)
  • 2021-02-02 16:24

    I found this small and free tool that fits most of my needs. http://www.wintestgear.com/products/MSSQLSchemaDiff/MSSQLSchemaDiff.html

    It's very basic but it shows you the schema differences of two databases. It doesn't have any fancy stuff like auto generated scripts to make the differences to go away and it doesn't compare any data.

    It's just a small, free utility that shows you schema differences :)

    0 讨论(0)
提交回复
热议问题