使用sql对比Mysql中数据库2个表结构

比较两个数据表的结构

SELECT
	column_name,
	max(
		CASE
		WHEN table_name = 'table1' AND table_schema = 'db1'  THEN
			'Yes'
		END
	) AS in_table_1,
	max(
		CASE
		WHEN table_name = 'table1' AND table_schema = 'db2' THEN
			'Yes'
		END
	) AS in_table_2
FROM
	information_schema. COLUMNS
WHERE
	(
		(
			table_schema = 'db1'
			AND table_name = 'table1'
		)
		OR (
			table_schema = 'db2'
			AND table_name = 'table1'
		)
	)
AND table_name IN ('table1', 'table1')
GROUP BY
	column_name
ORDER BY
	column_name;
References:
  1. mysql: compare structure of two tables
  2. Query to compare the structure of two tables in MySQL
posted @ 2019-08-11 21:01  五毛钱的饼  阅读(1257)  评论(0编辑  收藏  举报