Last active
December 25, 2015 16:29
-
-
Save paranoiq/7006834 to your computer and use it in GitHub Desktop.
vygeneruje SQL pro kontrolu integrity celé databáze, pokud někdo vypnul cizí klíče a rozbil data
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
SELECT | |
/*fk.CONSTRAINT_SCHEMA, | |
fk.CONSTRAINT_NAME, | |
fk.TABLE_NAME, | |
col.COLUMN_NAME, | |
fk.REFERENCED_TABLE_NAME, | |
col.REFERENCED_COLUMN_NAME,*/ | |
CONCAT('SELECT * FROM `', fk.TABLE_NAME, '` WHERE `', col.COLUMN_NAME, '` NOT IN (SELECT `', col.REFERENCED_COLUMN_NAME, '` FROM `', fk.REFERENCED_TABLE_NAME, '`);') AS query | |
FROM `REFERENTIAL_CONSTRAINTS` fk | |
JOIN KEY_COLUMN_USAGE col USING (CONSTRAINT_SCHEMA, CONSTRAINT_NAME) | |
WHERE fk.`CONSTRAINT_SCHEMA` = '{jméno databáze}' | |
ORDER BY fk.REFERENCED_TABLE_NAME; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment