Skip to content

Instantly share code, notes, and snippets.

@thejsj
Created October 7, 2020 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejsj/b6c8e1cae58efc402c297ce6948e4b74 to your computer and use it in GitHub Desktop.
Save thejsj/b6c8e1cae58efc402c297ce6948e4b74 to your computer and use it in GitHub Desktop.
Find all mysql tables with no primary key. Used to migrate old databases into Digital Ocean managed MySQL.
SELECT table_schema ,table_name FROM information_schema.columns
WHERE table_schema <> 'sys' AND table_schema <> 'information_schema' AND table_schema <> 'mysql' AND table_schema <> 'performance_schema'
GROUP BY table_schema ,table_name
HAVING sum(if (column_key in ('PRI', 'UNI'), 1, 0)) = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment