查询表未设置主键语句 mysql

134 阅读1分钟

查询表未设置主键语句 mysql

SELECT
	t.table_schema,
	t.table_name 
FROM
	information_schema.TABLES t
	LEFT JOIN information_schema.COLUMNS c ON t.table_schema = c.table_schema 
	AND t.table_name = c.table_name 
WHERE
	t.table_type = 'BASE TABLE' 
	AND t.table_schema NOT IN ( 'mysql', 'sys', 'performance_schema', 'information_schema', 'EMAIL', 'ERP_API_BAK', 'SCM_BAK', 'scm_prod', 'sywldb' ) 
GROUP BY
	t.table_schema,
	t.table_name 
HAVING
	sum(
IF
	( c.column_key = 'PRI', 1, 0 )) = 0;