Subject Re: [firebird-support] determining if a table has a primary key
Author Alexandre Benson Smith
Ed Dressel wrote:
> What's the SQL to get the primary key of a table? While I'm
> asking--the SQL for getting foreign keys as well.
>
> Thanks
> Ed Dressel
>
>

Do you want to see if a given table has a PK and it's name ??? If so try
this one:
select * from rdb$relation_constraints where rdb$constraint_type =
'PRIMARY KEY' and rdb$relation_name = 'YOUR_TABLE'

if you want to see the fields on the PK is based on try this:
select
i_s.rdb$field_name
from
rdb$relation_constraints rc join
rdb$indices i on (i.rdb$index_name = rc.rdb$index_name) join
rdb$index_segments i_s on (i_s.rdb$index_name = i.rdb$index_name)
where
rdb$constraint_type = 'PRIMARY KEY' and
rdb$relation_name = 'ESTADOICMS'

what do you want to know ??? what FK's a given table has ? wich tables
has FK to it ??

HTH

see you !

--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br