Richard2048
asked on
Postgres Foreign Keys
I wish to write a query that will return a list of foreign keys and the table to which they pertain.
For example:
- Given a table of 'customers' and a table of 'accounts', in which each customer can have 1 or more accounts
- The FK in accounts is a customer_id
How would I write a query to list the foreign key(s) in the accounts table along with the table to which said foreign key relates.
For exampe:
I want to query the 'accounts' table, so as to retrieve the customer_id as the FK and the customers table as the table linked to this FK.
Any ideas?
For example:
- Given a table of 'customers' and a table of 'accounts', in which each customer can have 1 or more accounts
- The FK in accounts is a customer_id
How would I write a query to list the foreign key(s) in the accounts table along with the table to which said foreign key relates.
For exampe:
I want to query the 'accounts' table, so as to retrieve the customer_id as the FK and the customers table as the table linked to this FK.
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect,
For the most part, all I have are single column references. The second query you posted certainly brought a smile to my face!
Thankyou!
For the most part, all I have are single column references. The second query you posted certainly brought a smile to my face!
Thankyou!
\d accounts