Skip to content

Instantly share code, notes, and snippets.

@dungmanh88
Created October 19, 2016 08:09
Show Gist options
  • Save dungmanh88/32a9969c8353ad934eed3bad2e131b6d to your computer and use it in GitHub Desktop.
Save dungmanh88/32a9969c8353ad934eed3bad2e131b6d to your computer and use it in GitHub Desktop.
Do all tables have primary key ?
select t.table_schema, t.table_name
from information_schema.tables t
left join information_schema.statistics s
on t.table_schema=s.table_schema and t.table_name=s.table_name and s.non_unique=0
where s.table_name is null and t.table_schema not in ('mysql', 'information_schema','performance_schema');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment