Skip to content

Instantly share code, notes, and snippets.

@faloi
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faloi/2218b1c98fcc40fff4d4 to your computer and use it in GitHub Desktop.
Save faloi/2218b1c98fcc40fff4d4 to your computer and use it in GitHub Desktop.
-- Foreign keys
use INFORMATION_SCHEMA;
select constraint_name, TABLE_NAME, REFERENCED_TABLE_NAME
from KEY_COLUMN_USAGE
where REFERENCED_TABLE_NAME is not null
-- Count of foreign keys with "FK_" prefix
use INFORMATION_SCHEMA;
select count(*)
from KEY_COLUMN_USAGE
where INSTR(constraint_name, 'FK_') > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment