SELECT TRIM(RDB$RELATION_FIELDS.RDB$FIELD_NAME) || ' (' ||
CASE WHEN ((SELECT COUNT(1)
FROM RDB$RELATION_CONSTRAINTS,
RDB$INDEX_SEGMENTS
WHERE RDB$INDEX_SEGMENTS.RDB$INDEX_NAME = RDB$RELATION_CONSTRAINTS.RDB$INDEX_NAME
AND RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY'
AND RDB$RELATION_CONSTRAINTS.RDB$RELATION_NAME = RDB$RELATION_FIELDS.RDB$RELATION_NAME
AND RDB$INDEX_SEGMENTS.RDB$FIELD_NAME = RDB$RELATION_FIELDS.RDB$FIELD_NAME) > 0)
THEN 'PK, ' ELSE TRIM('') END ||
CASE WHEN ((SELECT COUNT(1)
FROM RDB$RELATION_CONSTRAINTS,
RDB$INDEX_SEGMENTS
WHERE RDB$INDEX_SEGMENTS.RDB$INDEX_NAME = RDB$RELATION_CONSTRAINTS.RDB$INDEX_NAME
AND RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_TYPE = 'FOREIGN KEY'
AND RDB$RELATION_CONSTRAINTS.RDB$RELATION_NAME = RDB$RELATION_FIELDS.RDB$RELATION_NAME
AND RDB$INDEX_SEGMENTS.RDB$FIELD_NAME = RDB$RELATION_FIELDS.RDB$FIELD_NAME) > 0)
THEN 'FK, ' ELSE TRIM('') END ||
CASE RDB$FIELDS.RDB$FIELD_TYPE
WHEN 7 THEN 'smallint, '
WHEN 8 THEN 'integer, '
WHEN 9 THEN 'quad, '
WHEN 10 THEN 'float, '
WHEN 11 THEN 'd_float, '
WHEN 12 THEN 'date, '
WHEN 13 THEN 'time, '
WHEN 14 THEN 'char' || '(' || RDB$FIELDS.RDB$FIELD_LENGTH || '), '
WHEN 16 THEN 'int64, '
WHEN 27 THEN 'double, '
WHEN 35 THEN 'timestamp, '
WHEN 37 THEN 'varchar' || '(' || RDB$FIELDS.RDB$FIELD_LENGTH || '), '
WHEN 40 THEN 'cstring' || '(' || RDB$FIELDS.RDB$FIELD_LENGTH || '), '
WHEN 261 THEN 'blob, '
ELSE 'Não Identificado, ' END ||
CASE RDB$RELATION_FIELDS.RDB$NULL_FLAG
WHEN 1 THEN TRIM('Não Nulo') ELSE TRIM('Nulo') END || ')' AS Coluna
FROM RDB$RELATION_FIELDS
LEFT JOIN RDB$FIELDS ON RDB$RELATION_FIELDS.RDB$FIELD_SOURCE = RDB$FIELDS.RDB$FIELD_NAME
WHERE RDB$RELATION_FIELDS.RDB$RELATION_NAME = 'USUARIOS' -- Nome da Tabela