MariaDb - Find tables without primary key

Updated at by

Galera cluster doesn't support DELETE on tables without primary key. See Galera cluster known limitations

Following command shows a list of tables of tables without primary key

SELECT
    t.table_schema, t.table_name, engine
FROM
    information_schema.tables t
        INNER JOIN
    information_schema.columns c ON t.table_schema = c.table_schema
        AND t.table_name = c.table_name
GROUP BY t.table_schema , t.table_name
HAVING SUM(IF(column_key IN ('PRI'), 1, 0)) = 0;

Leave a comment