Skip to content

Instantly share code, notes, and snippets.

@mikemill
Created July 18, 2018 15:18
Show Gist options
  • Select an option

  • Save mikemill/ac5a7347b18aef0c0bfa179b9c95dde1 to your computer and use it in GitHub Desktop.

Select an option

Save mikemill/ac5a7347b18aef0c0bfa179b9c95dde1 to your computer and use it in GitHub Desktop.
MySQL Foreign Key references
SELECT
TABLE_NAME,
COLUMN_NAME,
CONSTRAINT_NAME,
REFERENCED_TABLE_NAME,
REFERENCED_COLUMN_NAME,
UPDATE_RULE,
DELETE_RULE
FROM
INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu
JOIN
INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS USING (
CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME,
TABLE_NAME, REFERENCED_TABLE_NAME)
WHERE
REFERENCED_TABLE_SCHEMA = 'launchpad' AND
REFERENCED_TABLE_NAME IN ('lpdays')
-- AND REFERENCED_COLUMN_NAME = 'TermID'
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment