MySQL查询表包含字段

针对MySQL查询某个表是否包含某个字段

SELECT
	TABLE_NAME 表名,
	TABLE_COMMENT 表备注,
	column_name 列名 ,
	DATA_LENGTH 表大小
FROM
	(
		SELECT
			c.TABLE_NAME,
			t.TABLE_COMMENT,
			c.column_name ,
			t.DATA_LENGTH
		FROM
			information_schema.COLUMNS c
			JOIN information_schema.TABLES t ON c.TABLE_NAME = t.TABLE_NAME 
		WHERE
			c.table_schema = 'databseName' 
	) a 
WHERE
	a.column_name = "fileName"  AND a.DATA_LENGTH > 0 GROUP BY a.TABLE_NAME;

databseName : 数据库名
fileName : 字段名

你可能感兴趣的:(MySQL,mysql,数据库)