Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Script to find Source and Destination of All Foreign Key Constraint

In this post, I am sharing a script to find all list of Foreign Keys with source and destination in PostgreSQL.

Using below script, you can easily find all foreign keys of a Postgres Database, and it is also handy for Database Architect to find the different references of a database server.
SELECT
 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'; 

Comments

Popular posts from this blog

Pgbadger Feature In Postgresql

ERROR: operator does not exist: text ->> unknown LINE 1: ...stomer' as customer_name,sales_info ->>'PRODUCTS' ->>'produc... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

rman interview and scenario based questions and answer and also rman(backup and recovery) discussions panel

7 Steps to configure BDR replication in postgresql

How to Use netstat (network statistics) command In Linux