Last active
March 24, 2019 20:08
-
-
Save adamelliotfields/8b27629c2a0ef2b68d86474b3f178815 to your computer and use it in GitHub Desktop.
SQL Select Tables without Primary Key in Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT tables.table_schema, tables.table_name | |
FROM tables | |
LEFT JOIN key_column_usage AS kcu ON ( | |
kcu.table_name = tables.table_name AND | |
kcu.constraint_schema = tables.table_schema AND | |
kcu.constraint_name = 'PRIMARY') | |
WHERE tables.table_schema = @db_name AND | |
kcu.constraint_name IS NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from http://moiseevigor.github.io/programming/2015/02/17/find-all-tables-without-primary-key-in-mysql.