Skip to content

Instantly share code, notes, and snippets.

@jayjanssen
Last active October 13, 2015 16:48
Show Gist options
  • Select an option

  • Save jayjanssen/4226660 to your computer and use it in GitHub Desktop.

Select an option

Save jayjanssen/4226660 to your computer and use it in GitHub Desktop.
All tables without PRIMARY keys
select all_tables.*
FROM
(select table_schema, table_name from information_schema.statistics group by table_schema, table_name ) all_tables
LEFT JOIN
(select table_schema, table_name from information_schema.statistics where index_name='PRIMARY' group by table_schema, table_name ) primary_tables
USING ( table_schema, table_name)
WHERE primary_tables.table_name is null;
@y-trudeau
Copy link

I use this one:
select CONCAT(t.table_schema,'.',t.table_name) as tbl, t.table_rows from information_schema.TABLES AS t LEFT JOIN information_schema.KEY_COLUMN_USAGE AS c ON (t.TABLE_NAME=c.TABLE_NAME AND c.CONSTRAINT_SCHEMA=t.TABLE_SCHEMA AND constraint_name='PRIMARY') WHERE t.table_schema not in ('information_schema','mysql') and t.table_rows > 0 and c.constraint_name is null and t.engine='innodb' order by 2 desc;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment