I have the following method to identify missing primary keys in a MySQL database schema:
USE information_schema;
SELECT xx.table_name
FROM (SELECT table_name, COUNT(*) FROM columns WHERE table_schema = @myDB GROUP BY table_name, column_key) xx
GROUP BY xx.table_name
HAVING COUNT(*) = 1;
I am not particularly enamored with the xx solution, because one can never be certain that a table with that name does not already exist. Does anyone know of a solution which is more elegant?