Subject Re: Find Primary Key for a table
Author Adam
--- In firebird-support@yahoogroups.com, "Steve Harp" <steve@...> wrote:
>
> Hi All,
>
> Is there a query I can execute against the system tables that will
> give me the fields contained in the primary key for a table?
>
> select the_fields
> from rdb$whatever
> where the_table = 'my_table_name'
>
> Thanks,
> Steve
>

Steve,

Start from here:

SELECT C.RDB$RELATION_NAME, I.RDB$FIELD_NAME
FROM RDB$RELATION_CONSTRAINTS C
JOIN RDB$INDEX_SEGMENTS I ON (C.RDB$INDEX_NAME = i.RDB$INDEX_NAME)
WHERE C.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY'
ORDER BY C.RDB$RELATION_NAME, I.RDB$FIELD_POSITION

Note that there is possibly more than one field in the primary key
constraint.

Adam