Re: Primary key and Foreign key
Date: 20 Sep 2002 12:14:18 -0700
Message-ID: <6dae7e65.0209201114.16758d27_at_posting.google.com>
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,
> 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
)
select
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