harveypekkar wrote:

I am trying to query the system table of firebird ( version 2.1) to obtain the list of table and fields wich use the primary key from another as foreign key.

Svein Erling Tysvær answers:

The following may help you:

select i.rdb$relation_name, iseg.rdb$field_name
  from rdb$relation_constraints rec
    join rdb$ref_constraints rfc on rec.rdb$constraint_name = rfc.rdb$constraint_name
    join rdb$relation_constraints rec2 on rfc.rdb$const_name_uq = rec2.rdb$constraint_name
    join rdb$index_segments iseg2 on rec2.rdb$index_name = iseg2.rdb$index_name
    join rdb$indices i2 on rec2.rdb$index_name = i2.rdb$index_name
    join rdb$indices i on rec.rdb$index_name = i.rdb$index_name
    join rdb$index_segments iseg on rec.rdb$index_name = iseg.rdb$index_name
  where i2.rdb$relation_name = :MyTableName
    and iseg2.rdb$field_name = :MyPKFieldName

Like this post? Share on: TwitterFacebookEmail

Related Articles


Firebird Community



Gems from Firebird Support list