Subject Re: Unique key fieldnames?
Author Steve Harp
--- In, "Steve Harp" <steve@h...> wrote:
> Hi All,
> Is there a IBO component method or a query I can use to get a list of
> the fieldnames of a specified table which are used in primary keys or
> unique indexes? For instance, if I have a table called MyTable with a
> primary key field of 'ID' and a unique index on the 'Name' field, how
> would I get a list (TStrings) of these two fieldnames?

I found something that seems to give me what I need:

select ri.rdb$index_name AS KeyName,
ri.rdb$relation_name AS TableName,
rs.rdb$field_name AS FieldName,
rs.rdb$field_position AS FieldPos
from rdb$indices ri
join rdb$relations rr on (rr.rdb$relation_name = ri.rdb$relation_name)
join rdb$index_segments rs on (rs.rdb$index_name = ri.rdb$index_name)
where (ri.rdb$unique_flag = 1) and
(rr.rdb$system_flag = 0)
Order by ri.RDB$Relation_Name, rs.rdb$index_name, rs.rdb$field_position;