Last active
October 13, 2015 16:48
-
-
Save jayjanssen/4226660 to your computer and use it in GitHub Desktop.
All tables without PRIMARY keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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;