Compare structures of two databases?

前端 未结 17 1532
我在风中等你
我在风中等你 2021-02-01 04:30

I wanted to ask whether it is possible to compare the complete database structure of two huge databases. We have two databases, the one is a development database, the other a p

相关标签:
17条回答
  • 2021-02-01 04:41

    I finally used a simple tool called "mysql structure compare" to solve this. It's for windows only, but it's free and it works..

    0 讨论(0)
  • 2021-02-01 04:45

    Depending on your database, the tools available vary.

    I use Embarcadero's ER/Studio for this. It has a Compare and Merge feature.

    There are plenty others, such as Toad for MySQL, that also have compare. Also agree on the Red-Gate suggestion, but never used it for MySQL.

    0 讨论(0)
  • 2021-02-01 04:47

    If you are using MySQL there is a free tool DB Matcher where you upload the structure of 2 .SQL files and it gives you the differences

    https://dbmatcher.com

    0 讨论(0)
  • 2021-02-01 04:48

    SQL Examiner Suite 2010 compares MySQL databases (both schema and data)

    0 讨论(0)
  • 2021-02-01 04:51

    For MySQL database you can compare view and tables (column name and column type) using this query:

    SET @firstDatabaseName = '[first database name]';
    SET @secondDatabaseName = '[second database name]';
    
    SELECT * FROM  
      (SELECT
          CONCAT(cl.TABLE_NAME, ' [', cl.COLUMN_NAME, ', ', cl.COLUMN_TYPE, ']') tableRowType
        FROM information_schema.columns cl,  information_schema.TABLES ss
        WHERE
          cl.TABLE_NAME = ss.TABLE_NAME AND
          cl.TABLE_SCHEMA = @firstDatabaseName AND
          ss.TABLE_TYPE IN('BASE TABLE', 'VIEW')
        ORDER BY
          cl.table_name ) AS t1
    LEFT JOIN                     
      (SELECT
          CONCAT(cl.TABLE_NAME, ' [', cl.COLUMN_NAME, ', ', cl.COLUMN_TYPE, ']') tableRowType
        FROM information_schema.columns cl,  information_schema.TABLES ss
        WHERE
          cl.TABLE_NAME = ss.TABLE_NAME AND
          cl.TABLE_SCHEMA = @secondDatabaseName AND
          ss.TABLE_TYPE IN('BASE TABLE', 'VIEW')
        ORDER BY
          cl.table_name ) AS t2 ON t1.tableRowType = t2.tableRowType
    WHERE 
      t2.tableRowType IS NULL        
    UNION 
    SELECT * FROM  
      (SELECT
          CONCAT(cl.TABLE_NAME, ' [', cl.COLUMN_NAME, ', ', cl.COLUMN_TYPE, ']') tableRowType
        FROM information_schema.columns cl,  information_schema.TABLES ss
        WHERE
          cl.TABLE_NAME = ss.TABLE_NAME AND
          cl.TABLE_SCHEMA = @firstDatabaseName AND
          ss.TABLE_TYPE IN('BASE TABLE', 'VIEW')
        ORDER BY
          cl.table_name ) AS t1
    RIGHT JOIN                     
      (SELECT
          CONCAT(cl.TABLE_NAME, ' [', cl.COLUMN_NAME, ', ', cl.COLUMN_TYPE, ']') tableRowType
        FROM information_schema.columns cl,  information_schema.TABLES ss
        WHERE
          cl.TABLE_NAME = ss.TABLE_NAME AND
          cl.TABLE_SCHEMA = @secondDatabaseName AND
          ss.TABLE_TYPE IN('BASE TABLE', 'VIEW')
        ORDER BY
          cl.table_name ) AS t2 ON t1.tableRowType = t2.tableRowType
    WHERE 
      t1.tableRowType IS NULL;
    

    If you prefer using tool with UI you can also use this script https://github.com/dlevsha/compalex which can compare tables, views, keys etc.

    Compalex is a lightweight script to compare two database schemas. It supports MySQL, MS SQL Server and PostgreSQL.

    Screenshot (compare tables)

    0 讨论(0)
  • 2021-02-01 04:51

    Red-Gate SQL Compare is a great tool that will do this for you. I have used this for years with great success. It has saved me thousands of hours of work.

    They also have a tool that will compare data as well. The product I mentioned above compares schema.

    www-red-gate.com

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