版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Leon_liuqinburen/article/details/79126084
查看实例中哪些表没有主键
select t1.table_schema,t1.table_name from information_schema.tables t1
left outer join
information_schema.TABLE_CONSTRAINTS t2
on t1.table_schema = t2.TABLE_SCHEMA and t1.table_name = t2.TABLE_NAME and t2.CONSTRAINT_NAME in
('PRIMARY')
where t2.table_name is null and t1.TABLE_SCHEMA not in ('information_schema','performance_schema','test','mysql', 'sys');
查看实例中哪些表有主键
select t1.table_schema,t1.table_name from information_schema.tables t1
left outer join
information_schema.TABLE_CONSTRAINTS t2
on t1.table_schema = t2.TABLE_SCHEMA and t1.table_name = t2.TABLE_NAME and t2.CONSTRAINT_NAME in
('PRIMARY')
where t2.table_name is not null and t1.TABLE_SCHEMA not in ('information_schema','performance_schema','test','mysql', 'sys');