Primary Keys without auto increment (MYSQL)

How do you check that all primary keys have an auto increment function? Well here is how to do it.

SELECT distinct
    u.table_name, u.column_name, u.constraint_name, c.extra
FROM
    INFORMATION_SCHEMA.KEY_COLUMN_USAGE u, INFORMATION_SCHEMA.COLUMNS  c
WHERE
	u.TABLE_NAME=c.TABLE_NAME
    and u.COLUMN_NAME=c.COLUMN_NAME
    AND u.TABLE_SCHEMA=c.TABLE_SCHEMA
    AND u.CONSTRAINT_NAME = 'PRIMARY'
    AND u.TABLE_SCHEMA = 'mytoll'
    AND c.extra <> 'auto_increment';
 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.