Subject | for NIBUs - query to show all field detail |
---|---|
Author | csswa |
Post date | 2002-04-27T07:23:20Z |
I just came across this and thought it would be very useful for other
newbies like me.
It's from HowToDoThings.com, author is Peter Morris, from September
2001. Thanks, Peter! A great insight into querying system tables.
Original text follows.
------------
A complicated SQL query I had to work out to tell me information
about the current database.
This query will tell you
TableName, FieldName, FieldType, FieldSubType, ForeignTableName,
ForeignFieldName
select distinct
Rel.rdb$relation_name TableName,
Rel.rdb$field_name FieldName,
Fld.rdb$field_type FieldType,
Fld.rdb$field_sub_type FieldSubType,
FCon.rdb$Relation_Name ForeignTableName,
FIseg.rdb$Field_Name ForeignFieldName
from
rdb$relation_fields Rel
left join
rdb$relation_constraints Con
on
(Con.rdb$relation_name = Rel.rdb$relation_name and
Con.rdb$constraint_type like 'FOREIGN%')
left join
rdb$indices IDX
on
IDX.rdb$index_name = Con.rdb$index_name
left join
rdb$index_segments ISeg
on
(ISeg.rdb$index_name = Idx.rdb$index_name and
ISeg.rdb$Field_Name = Rel.rdb$field_name)
left join
rdb$Relation_Constraints FCon
on
FCon.rdb$index_name = Idx.rdb$Foreign_Key
left join
rdb$index_segments FIseg
on
(FISeg.rdb$index_name = Idx.rdb$Foreign_key and
FISeg.rdb$Field_Position = ISeg.rdb$Field_Position),
rdb$fields Fld,
rdb$Relation_Fields RFld
where
Rel.rdb$relation_name not like 'RDB$%' and
Fld.rdb$field_name = Rel.rdb$field_source and
RFld.rdb$Relation_Name = Rel.rdb$Relation_name and
RFld.rdb$field_name = Rel.rdb$field_name
order by
Rel.rdb$relation_name,
RFld.rdb$Field_ID;
newbies like me.
It's from HowToDoThings.com, author is Peter Morris, from September
2001. Thanks, Peter! A great insight into querying system tables.
Original text follows.
------------
A complicated SQL query I had to work out to tell me information
about the current database.
This query will tell you
TableName, FieldName, FieldType, FieldSubType, ForeignTableName,
ForeignFieldName
select distinct
Rel.rdb$relation_name TableName,
Rel.rdb$field_name FieldName,
Fld.rdb$field_type FieldType,
Fld.rdb$field_sub_type FieldSubType,
FCon.rdb$Relation_Name ForeignTableName,
FIseg.rdb$Field_Name ForeignFieldName
from
rdb$relation_fields Rel
left join
rdb$relation_constraints Con
on
(Con.rdb$relation_name = Rel.rdb$relation_name and
Con.rdb$constraint_type like 'FOREIGN%')
left join
rdb$indices IDX
on
IDX.rdb$index_name = Con.rdb$index_name
left join
rdb$index_segments ISeg
on
(ISeg.rdb$index_name = Idx.rdb$index_name and
ISeg.rdb$Field_Name = Rel.rdb$field_name)
left join
rdb$Relation_Constraints FCon
on
FCon.rdb$index_name = Idx.rdb$Foreign_Key
left join
rdb$index_segments FIseg
on
(FISeg.rdb$index_name = Idx.rdb$Foreign_key and
FISeg.rdb$Field_Position = ISeg.rdb$Field_Position),
rdb$fields Fld,
rdb$Relation_Fields RFld
where
Rel.rdb$relation_name not like 'RDB$%' and
Fld.rdb$field_name = Rel.rdb$field_source and
RFld.rdb$Relation_Name = Rel.rdb$Relation_name and
RFld.rdb$field_name = Rel.rdb$field_name
order by
Rel.rdb$relation_name,
RFld.rdb$Field_ID;