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

    t.table_schema, t.table_name, engine
    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;

Share on FacebookShare on Facebook Share on TwitterShare on Twitter

Leave a comment