how to compare/validate sql schema

后端 未结 11 675
后悔当初
后悔当初 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:25

    Make a table and store your version number in there. Just make sure you update it as necessary.

    CREATE TABLE version (
        version VARCHAR(255) NOT NULL
    )
    INSERT INTO version VALUES ('v1.0');
    

    You can then check the version number stored in the database matches the application code during your app's setup or wherever is convenient.

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

    You can now use my SQL Admin Studio for free to run a Schema Compare, Data Compare and Sync the Changes. No longer requires a license key download from here http://www.simego.com/Products/SQL-Admin-Studio

    Also works against SQL Azure.

    [UPDATE: Yes I am the Author of the above program, as it's now Free I just wanted to Share it with the community]

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

    SQL Compare by Red Gate.

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

    I hope I can help - this is the article I suggest reading:

    Compare SQL Server database schemas automatically

    It describes how you can automate the SQL Server schema comparison and synchronization process using T-SQL, SSMS or a third party tool.

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

    You didn't mention which RDMBS you're using: if the INFORMATION SCHEMA views are available in your RDBMS, and if you can reference both schemas from the same host, you can query the INFORMATION SCHEMA views to identify differences in: -tables -columns -column types -constraints (e.g. primary keys, unique constraints, foreign keys, etc)

    I've written a set of queries for exactly this purpose on SQL Server for a past job - it worked well to identify differences. Many of the queries were using LEFT JOINs with IS NULL to check for the absence of expected items, others were comparing things like column types or constraint names.

    It's a little tedious, but its possible.

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