пʼятниця, 18 січня 2013 р.

MySQL - Finding tables without primary keys

It is always important to have primary keys when you're in SQL world. I have found a nice way find to find those culprit tables who don't have it. And just modified a bit added "engine" column. So here it is:

SELECT table_catalog, table_schema, table_name, engine
  FROM information_schema.tables
    WHERE (table_catalog, table_schema, table_name) NOT IN
          (SELECT table_catalog, table_schema, table_name
               FROM information_schema.table_constraints
               WHERE constraint_type = 'PRIMARY KEY')
      AND table_schema NOT IN ('information_schema', 'pg_catalog');

Немає коментарів:

Дописати коментар