Skip to content

Instantly share code, notes, and snippets.

@mikehins
Last active December 1, 2022 21:09
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 mikehins/9492d78ab358abbdce8b252fa6a46b05 to your computer and use it in GitHub Desktop.
Save mikehins/9492d78ab358abbdce8b252fa6a46b05 to your computer and use it in GitHub Desktop.
select concat(fks.constraint_schema, '.', fks.table_name) as foreign_table,
'->' as rel,
concat(fks.unique_constraint_schema, '.', fks.referenced_table_name)
as primary_table,
fks.constraint_name,
group_concat(kcu.column_name
order by position_in_unique_constraint separator ', ')
as fk_columns
from information_schema.referential_constraints fks
join information_schema.key_column_usage kcu
on fks.constraint_schema = kcu.table_schema
and fks.table_name = kcu.table_name
and fks.constraint_name = kcu.constraint_name
where fks.constraint_schema = 'novapro_aldego'
group by fks.constraint_schema,
fks.table_name,
fks.unique_constraint_schema,
fks.referenced_table_name,
fks.constraint_name
order by fks.constraint_schema,
fks.table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment