| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Primary key and Foreign key
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 - 14:14:18 CDT
![]() |
![]() |