查询数据库内不同表间相同字段不同类型,不同长度的所有字段

时间:2022-01-01 13:52:49

需求:二次开发整理数据库

查询数据库内不同表间相同字段不同类型,不同长度的所有字段

SELECT a.TABLE_NAME,a.COLUMN_NAME,a.DATA_TYPE,a.CHARACTER_MAXIMUM_LENGTH

FROM information_schema.COLUMNS a 
WHERE a.TABLE_SCHEMA = 'ec_business'
AND A.COLUMN_NAME in (
select c.COLUMN_NAME from (
SELECT *,COUNT(b.COLUMN_NAME) AS COUNT FROM  (
SELECT a.TABLE_NAME,a.COLUMN_NAME,a.DATA_TYPE,a.CHARACTER_MAXIMUM_LENGTH
FROM information_schema.COLUMNS a 
WHERE a.TABLE_SCHEMA = 'ec_business'
GROUP BY a.DATA_TYPE,a.COLUMN_NAME,a.CHARACTER_MAXIMUM_LENGTH
ORDER BY a.COLUMN_NAME
) b
GROUP BY b.COLUMN_NAME
HAVING COUNT>1
) c
)
GROUP BY a.DATA_TYPE,a.COLUMN_NAME,a.CHARACTER_MAXIMUM_LENGTH

  ORDER BY a.COLUMN_NAME