how to compare/validate sql schema

后端 未结 11 678
后悔当初
后悔当初 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条回答
  •  -上瘾入骨i
    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.

提交回复
热议问题