This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a script to find all the tables without having a Primary Key in MySQL.
This script is very important because Primary Key is a one of a major part of the table. I never recommended like creating a table without Primary Key.
Using below script, and find the tables that do not have a primary key:
1 2 3 4 5 6 7 8 9 |
select table_schema ,table_name from information_schema.columns where table_schema = 'SCHEMA_NAME' group by table_schema ,table_name having sum(if (column_key in ('PRI', 'UNI'), 1, 0)) = 0 |