where
table_schema not in
('mysql','information_schema','performance_schema','test','sys')
and TABLE_NAME not in (
select table_name
from
information_schema.table_constraints t
join information_schema.key_column_usage k using (
constraint_name,table_schema,table_name)
where
t.constraint_type = 'PRIMARY KEY'
and t.table_schema not in
('mysql','information_schema','performance_schema','test','sys')
);
#查询指定库下没有 PK 的表
select table_schema,table_name from information_schema.TABLES
where
table_schema = 'yf' #替换需要查询
的库名
and TABLE_NAME not in (
select table_name
from
information_schema.table_constraints t
join information_schema.key_column_usage k using (
constraint_name,table_schema,table_name)
where
t.constraint_type = 'PRIMARY KEY'
and t.table_schema = 'yf' #替换需要查询
的库名
);
#通过系统视图找出全库下(除系统表以外的)有主键约束或主键索引的表
select * from information_schema.table_constraints where
CONSTRAINT_TYPE='PRIMARY KEY' and TABLE_SCHEMA not in
('mysql','information_schema','performance_schema','test','sys');
1.6 unique---通过系统视图找出全库下(除系统以外的)没有唯一约束或没有唯一索引的表
select table_schema,table_name from information_schema.TABLES
where
table_schema not in
('mysql','information_schema','performance_schema','test','sys')
and TABLE_NAME not in (
select table_name
from
information_schema.table_constraints t
join information_schema.key_column_usage k using (
constraint_name,table_schema,table_name)
where
t.constraint_type = 'UNIQUE'
and t.table_schema not in
('mysql','information_schema','performance_schema','test','sys')
);
#通过系统视图找出全库下(除系统以外的)有唯一约束或唯一索引的表
select * from information_schema.table_constraints where
评论