Created
September 18, 2010 17:19
-
-
Save julp/585871 to your computer and use it in GitHub Desktop.
try to guess tables dependencies via information_schema/foreign keys
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 DISTINCT t.table_name, rc.referenced_table_name | |
FROM information_schema.tables t | |
JOIN information_schema.table_constraints tc USING (table_schema, table_name) | |
LEFT JOIN information_schema.referential_constraints rc ON tc.table_schema = rc.constraint_schema AND tc.table_name = rc.table_name | |
WHERE t.table_schema='$DB' | |
/*AND t.table_name IN ('$TABLE1', '$TABLE2')*/ | |
AND (tc.constraint_type = 'FOREIGN KEY' OR (rc.table_name IS NULL AND rc.constraint_schema IS NULL)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment