Re: Primary key and Foreign key
Date: 20 Sep 2002 12:14:18 -0700
antonino_parisi_at_lycos.it (Antonino) wrote in message news:<bcfcea66.0209200107.4abaeaa_at_posting.google.com>...
> 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,
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,
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'
REFTABNAME FKS PKS
------------ ---------- ----------
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