Subject Re: [firebird-support] How can I get field constraints like Oracle All_Constraints view ...
Author Ivan Cruz
cicerobillo wrote:

>Hi!
>
>
>Can I sugest to create Views from System Tables in order to facilitate
>data recovery from System tables?
>
>
>
Cicero,

I believe it's a great idea. We can even start a "system views library"
right now in that thread. My first contribution:

------------------------------------------------
create view sysv$basicfieldlist as
select r.rdb$relation_name,
rf.rdb$field_position,
rf.rdb$field_name,
f.rdb$field_type,
t.rdb$type_name,
f.rdb$field_length,
f.rdb$field_scale,
rf.rdb$default_source,
rf.rdb$null_flag
from rdb$relations r
join rdb$relation_fields rf on r.rdb$relation_name =
rf.rdb$relation_name
join rdb$fields f on rf.rdb$field_source = f.rdb$field_name
join rdb$types t on f.rdb$field_type = t.rdb$type and
t.rdb$field_name = 'RDB$FIELD_TYPE'
where r.rdb$system_flag = 0 and
r.rdb$relation_name not like 'SYSV$%'
--------------------------------------------------------------------

Using that view to get all fields from all "non-system" relations (tables
and other views):

select * from sysv$basicfieldlist
order by rdb$relation_name, rdb$field_position

To get fields from a specĂ­fic table:

select * from sysv$basicfieldlist
where rdb$relation_name = 'TABLENAME'
order by rdb$field_position

Ivan.