Advertisement
koldaev

Show tables without primary keys

Sep 17th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.61 KB | None | 0 0
  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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement