比较两个数据表的结构

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

相关文章:

  • 2021-06-17
  • 2021-03-29
  • 2021-11-30
  • 2021-06-30
  • 2021-10-16
  • 2022-02-18
  • 2021-12-04
  • 2021-12-16
猜你喜欢
  • 2021-07-12
  • 2021-10-27
  • 2021-10-16
  • 2021-10-16
  • 2021-12-08
  • 2022-12-23
  • 2021-09-21
相关资源
相似解决方案