In this post, I provide one script to find all list of Foreign Key with source and destination in PostgreSQL.
I am sharing this kind of DBA script because in some situation it helps lots.
Using this script you can easily find all foreign key of a Postgres Database and its very useful for Database Architecture to find out different references.
tc.constraint_name AS ForeignKeyConstraintName
,tc.table_name AS TableName
,kcu.column_name AS ColumnName
,ccu.table_name AS ForeignKeyTableName
,ccu.column_name AS ForeignKeyColumn
FROM information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
WHERE tc.constraint_type = 'FOREIGN KEY';
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.