Subject Re: [firebird-support] Determining column structure in a Firebird table
Author Ann W. Harrison
Csaba wrote:
> I'd like to be able to determine the column
> types for each column of a table. (I think) I am
> after a correspondence similar to:
> column1Name => VARCHAR(7)
> column2Name => INTEGER PRIMARY KEY
> and so on.
> I've looked through all the tables mentioned at
> and I can get all the table columns (headers) from
> rdb$relation_fields.rdb$field_name =
> rdb$relations.rdb$relation_name

Look at RDB$FIELDS which is linked to RDB$RELATION_FIELDS
through the RDB$FIELD_SOURCE field.

rdb$relation_fields.rdb$field_source = rdb$fields.rdb$field_name

The types are stored in numeric form, unfortunately based on the
VAX/VMS data types, but you can probably sort through that.

To get the primary key information you need to check the system
table RDB$RELATION_CONSTRAINTS. That will also tell you about
unique and not null constraints - but only at the table level.
For unique and primary key constraints, you need to get the
index name from RDB$RELATION_CONSTRAINTS and look up the fields
for the null constraint.

Foreign key constraints are kept in RDB$REF_CONSTRAINTS and also
need a bit of cross referencing to get the full set of fields involved.

Helen Borrie's book "The Firebird Book" from Apress available through
the IBPhoenix web site is a great source of information about Firebird
system tables.

Good luck