Created
July 11, 2021 01:17
-
-
Save selfagency/1b39b7f81696597427c38dc80ae41140 to your computer and use it in GitHub Desktop.
[find all tables without primary keys]
This file contains hidden or 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
USE INFORMATION_SCHEMA; | |
SELECT | |
TABLES.table_name | |
FROM TABLES | |
LEFT JOIN KEY_COLUMN_USAGE AS c | |
ON ( | |
TABLES.TABLE_NAME = c.TABLE_NAME | |
AND c.CONSTRAINT_SCHEMA = TABLES.TABLE_SCHEMA | |
AND c.constraint_name = 'PRIMARY' | |
) | |
WHERE | |
TABLES.table_schema <> 'information_schema' | |
AND TABLES.table_schema <> 'performance_schema' | |
AND TABLES.table_schema <> 'mysql' | |
AND c.constraint_name IS NULL; | |
add primary key | |
ALTER TABLE wp_yoast_seo_meta ADD PRIMARY KEY(object_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment