如何查询没有主键的表

select table_schema,table_name
  FROM INFORMATION_SCHEMA.TABLES b
  WHERE
  b.TABLE_SCHEMA not in ('METRICS_SCHEMA','mysql','INFORMATION_SCHEMA','PERFORMANCE_SCHEMA','test') and table_type='BASE TABLE' and
  (table_schema, table_name) not in
  (select TABLE_SCHEMA,TABLE_NAME from
  (select TABLE_SCHEMA,TABLE_NAME,INDEX_NAME,GROUP_CONCAT(COLUMN_NAME) as c,group_concat(NULLABLE) as n
  from INFORMATION_SCHEMA.STATISTICS
  where NON_UNIQUE=0 and TABLE_SCHEMA not in ('METRICS_SCHEMA','mysql','INFORMATION_SCHEMA','PERFORMANCE_SCHEMA','test')
  group by 1,2,3) as tmp
  where tmp.n not like '%YES%');
2 个赞