Script to Find Table with no Primary Keys in MySQL

The script will list all of your tables that don't have a primary key on them. This is important to know, not only because the lack of primary keys affects performance and data accuracy in general.

select table_schema, table_name
  from information_schema.columns
 where table_schema = 'SCHEMA_NAME'
 group by table_schema, table_name
having sum(if (column_key in ('PRI', 'UNI'), 1, 0)) = 0;