Обсуждение: SQL Query for Foreign constraint

Поиск
Список
Период
Сортировка

SQL Query for Foreign constraint

От
Bhim Kumar
Дата:
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi sir</span><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">CurrentlyI am using following query on mysql :</div><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">*SHOW TABLES;   ---> To get list of table in a particular
db.</div><divstyle="font-family:arial,sans-serif;font-size:13px"> *
SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage WHERE constraint_schema ='myDBName';</div><div
style="font-family:arial,sans-serif;font-size:13px">    --->  to get foreign constraint information.</div><div
style="font-family:arial,sans-serif;font-size:13px">*SHOW INDEX FROM myTableName FROM myDBName;</div><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">Iam required to get above information from postgres.</div><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">I didn't find postgres query corresponding to above mysql query to
fetchcorresponding information.</div><div style="font-family:arial,sans-serif;font-size:13px"><br /></div><div
style="font-family:arial,sans-serif;font-size:13px">PS : help me for above query in postgres.</div><div
style="font-family:arial,sans-serif;font-size:13px"><br/></div><div
style="font-family:arial,sans-serif;font-size:13px">BestRegards.</div><div
style="font-family:arial,sans-serif;font-size:13px">Bhim</div></div> 

Re: SQL Query for Foreign constraint

От
Igor Neyman
Дата:

From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Bhim Kumar
Sent: Thursday, March 20, 2014 4:01 AM
To: pgsql-sql@postgresql.org
Subject: [SQL] SQL Query for Foreign constraint

Hi sir

Currently I am using following query on mysql :

* SHOW TABLES;   ---> To get list of table in a particular db.
*
SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage WHERE constraint_schema ='myDBName';
    --->  to get foreign constraint information.
* SHOW INDEX FROM myTableName FROM myDBName;

I am required to get above information from postgres.

I didn't find postgres query corresponding to above mysql query to fetch corresponding information.

PS : help me for above query in postgres.

Best Regards.
Bhim


Get familiar with INFORMATION_SCHEMA, it has all the information you need.
There is also pg_catalog wich has this info (and more) on a bit "lower" level.

Regards,
Igor Neyman