Re: Primary key and Foreign key

From: Lennart Jonsson <>
Date: 20 Sep 2002 12:14:18 -0700
Message-ID: <> (Antonino) wrote in message news:<>...
> Hi to all,
> I've read the problem about the PK and FK;
> but, is there a way to ask to the server
> which are the Foreign-Keys of a table,
> whith a standard SQL Query,
> or programming in C++ (Borland Builder)?
> Thanks in advance,
> Antonino.

You can find the information in the catalog of the db. For db2 you could do something like:

create table dummy1 (x integer not null primary key)

create table dummy2 (

    xx integer not null primary key,
    yy integer,
    constraint zz foreign key(yy) references dummy1 )


    reftabname, substr(FK_COLNAMES,1,10) as fks, substr(PK_COLNAMES,1,10) as pks from

    syscat.references where tabname = 'DUMMY2'

------------ ---------- ----------
DUMMY1 YY X   1 record(s) selected.

The look of the catalog tables probably varies between vendors(?), but every RDBMS should have a catalog from which you can extract such info

/Lennart Received on Fri Sep 20 2002 - 21:14:18 CEST

Original text of this message