Subject Re: [firebird-support] How to get the the tables and the columns of a Foreign Key?
Author Walter R. Ojeda Valiente
Thank you very much SET.

Yes, it will be useful. No exactly what I was looking for but good enough for know the names of the tables and the columns involved.

Greetings.

Walter.


On Tue, May 30, 2017 at 3:38 AM, Svein Erling Tysvær setysvar@... [firebird-support] <firebird-support@yahoogroups.com> wrote:
 

Hopefully this can get you started (though since your key consists of two fields, I would expect it to return four rows, not one row with two tables and four fields):

select iChild.rdb$Relation_name, isChild.rdb$field_name, iMain.rdb$relation_name, isMain.rdb$field_name
from rdb$indices iChild
join rdb$index_segments isChild on iChild.rdb$index_name = isChild.rdb$index_name
join rdb$indices iMain on iChild.rdb$Foreign_key = iMain.rdb$index_name
join rdb$index_segments isMain on iMain.rdb$index_name = isMain.rdb$index_name
where iChild.rdb$index_name = 'FK_ADHERENTES'

HTH,
Set

2017-05-30 7:10 GMT+02:00 'Walter R. Ojeda Valiente' sistemas2000profesional@gmail. com [firebird-support] <firebird-support@yahoogroups. com>:


Hello everybody

I had defined a Foreign Key as:

ALTER TABLE ADHERENTES 
ADD CONSTRAINT FK_ADHERENTES 
FOREIGN KEY (ADH_SERVID, ADH_IDECAB) 
REFERENCES CLIENTES(CLI_SERVID, CLI_IDENTI) 
ON DELETE CASCADE 
ON UPDATE CASCADE;

Of course, that work very well.

However, after watching the system tables I can not find a simple way to build a SELECT what can give me the name of the tables and the columns involved. Something as:

SELECT ... something

Result:
ADHERENTES, ADH_SERVID, ADH_IDECAB, CLIENTES, CLI_SERVID, CLI_IDENTI

Can somebody tell me how to get that result?

Thank you very much in advance.

Greetings.

Walter.