统计数据库 所有表有没有指定字段

SELECT
	ist.TABLE_NAME,
	ist.table_comment,
	missing_column1,
	missing_column2,
	missing_column3,
	missing_column4,
	missing_column5
FROM
	information_schema.TABLES ist
	-- sys_org_code
	LEFT JOIN (
	SELECT
		TABLE_NAME,
		'sys_org_code' AS missing_column1
	FROM
		information_schema.TABLES 
	WHERE
		TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
		
		AND TABLE_NAME NOT IN ( SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
			AND COLUMN_NAME = 'sys_org_code' -- 替换为你要排除的字段名
		)) soc ON soc.TABLE_NAME = ist.TABLE_NAME
	-- create_by
	LEFT JOIN (
	SELECT
		TABLE_NAME,
		'create_by' AS missing_column2
	FROM
		information_schema.TABLES 
	WHERE
		TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
		
		AND TABLE_NAME NOT IN ( SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
			AND COLUMN_NAME = 'create_by' -- 替换为你要排除的字段名
		)) cb ON cb.TABLE_NAME = ist.TABLE_NAME
	-- create_time
	LEFT JOIN (
	SELECT
		TABLE_NAME,
		'create_time' AS missing_column3
	FROM
		information_schema.TABLES 
	WHERE
		TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
		
		AND TABLE_NAME NOT IN ( SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
			AND COLUMN_NAME = 'create_time' -- 替换为你要排除的字段名
		)) ct ON ct.TABLE_NAME = ist.TABLE_NAME
	-- update_by
	LEFT JOIN (
	SELECT
		TABLE_NAME,
		'update_by' AS missing_column4
	FROM
		information_schema.TABLES 
	WHERE
		TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
		
		AND TABLE_NAME NOT IN ( SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
			AND COLUMN_NAME = 'update_by' -- 替换为你要排除的字段名
		)) ub ON ub.TABLE_NAME = ist.TABLE_NAME
	-- update_time
	LEFT JOIN (
	SELECT
		TABLE_NAME,
		'update_time' AS missing_column5
	FROM
		information_schema.TABLES 
	WHERE
		TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
		
		AND TABLE_NAME NOT IN ( SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'gas_test' -- 替换为你的数据库名
			AND COLUMN_NAME = 'update_time' -- 替换为你要排除的字段名
		)) ut ON ut.TABLE_NAME = ist.TABLE_NAME 
WHERE
	ist.table_schema = 'gas_test' -- 替换为你的数据库名

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值