Show tables without primary keys

koldaev Sep 17th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select tab.table_schema as database_name,
  2.        tab.table_name
  3. from information_schema.tables tab
  4. left join information_schema.table_constraints tco
  5.           on tab.table_schema = tco.table_schema
  6.           and tab.table_name = tco.table_name
  7.           and tco.constraint_type = 'PRIMARY KEY'
  8. where tco.constraint_type is null
  9.       and tab.table_schema not in('mysql', 'information_schema',
  10.                                   'performance_schema', 'sys')
  11.       and tab.table_type = 'BASE TABLE'
  12. --      and tab.table_schema = 'sakila' -- put schema name here
  13. order by tab.table_schema,
  14.          tab.table_name;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand