duxbpq
Last Updated: February 25, 2016
·
1.475K
· moiseevigor
2e1e340e378a26f2c69c6dd418060374

Find all tables without primary key in MySQL

USE INFORMATION_SCHEMA;
SELECT 
    TABLES.table_name
FROM TABLES
LEFT JOIN KEY_COLUMN_USAGE AS c 
ON (
       TABLES.TABLE_NAME = c.TABLE_NAME
   AND c.CONSTRAINT_SCHEMA = TABLES.TABLE_SCHEMA
   AND c.constraint_name = 'PRIMARY'
)
WHERE 
    TABLES.table_schema != 'infomation_schema'
AND c.constraint_name IS NULL;
Say Thanks
Respond