Skip to content

Instantly share code, notes, and snippets.

@adfinlay
Created December 30, 2014 12:46
Show Gist options
  • Save adfinlay/89f1b3971be696eb774c to your computer and use it in GitHub Desktop.
Save adfinlay/89f1b3971be696eb774c to your computer and use it in GitHub Desktop.
Get all MySQL tables without primary or unique keys
SELECT t.table_schema,t.table_name,engine
FROM information_schema.tables t INNER JOIN information_schema .columns c
on t.table_schema=c.table_schema and t.table_name=c.table_name
GROUP BY t.table_schema,t.table_name
HAVING sum(if(column_key in ('PRI','UNI'), 1,0)) =0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment