Thread: SQL Query for Foreign constraint

SQL Query for Foreign constraint

From
Bhim Kumar
Date:
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

Re: SQL Query for Foreign constraint

From
Raymond O'Donnell
Date:
On 20/03/2014 07:48, Bhim Kumar wrote:
> Hi sir
>
> Currently I am using following query on mysql :
>
> * SHOW TABLES;   ---> To get list of table in a particular db.

Assuming you're using psql, did you take the advice you're given on
connection and type "help"?

Anyway, to see a list of tables just enter:

 \d

Lots of handy backslash commands are available - \? will tell you more,
as will the fine manual:

  http://www.postgresql.org/docs/9.3/static/app-psql.html

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie


Re: SQL Query for Foreign constraint

From
Andy Colson
Date:
On 3/20/2014 4:45 PM, Raymond O'Donnell wrote:
> On 20/03/2014 07:48, Bhim Kumar wrote:
>> Hi sir
>>
>> Currently I am using following query on mysql :
>>
>> * SHOW TABLES;   ---> To get list of table in a particular db.
>
> Assuming you're using psql, did you take the advice you're given on
> connection and type "help"?
>
> Anyway, to see a list of tables just enter:
>
>   \d
>
> Lots of handy backslash commands are available - \? will tell you more,
> as will the fine manual:
>
>    http://www.postgresql.org/docs/9.3/static/app-psql.html
>
> Ray.
>
>

Yep, and if you are writing code, then all that info is in the
information_schema.

try:
select * from information_schema.tables
and
select * from information_schema.columns
etc.

-Andy