Lo prometido es deuda. Os dejo el código del Store Procedure para quien quiera utilizarlo.
Además de a mi, quien le de utilidad podrá darselas a AI , a Jhony y al IBExpert concretamente a su opción de SQL Monitor.
Un saludo
Código SQL
[-]
CREATE PROCEDURE Z_TABLAS
RETURNS (
TABLA VARCHAR(20),
POSICION INTEGER,
CAMPO VARCHAR(20),
TIPO VARCHAR(25),
LONGITUD INTEGER,
DECIMALES INTEGER,
PERMITE_NULOS CHAR(2),
PK INTEGER,
FK VARCHAR(50),
DESCRIPCION VARCHAR(500))
AS
declare variable wtipo integer;
declare variable subtipo integer;
declare variable wprecision integer;
declare variable escala integer;
declare variable nulo integer;
begin
for
Select
RF.RDB$Relation_Name TABLA,
RF.RDB$Field_Name CAMPO,
RF.RDB$Field_Position POSICION,
RF.RDB$Description DESCRIPCION,
F.RDB$Field_Type,
F.RDB$Field_Sub_Type,
F.RDB$Field_Length,
F.RDB$Field_Precision,
F.RDB$Field_Scale,
RF.RDB$Null_Flag
From RDB$Relation_Fields RF
Left Join RDB$Fields F On RF.RDB$Field_Source = F.RDB$Field_Name
Where RF.RDB$System_Flag = 0
order by
RF.RDB$Relation_Name,RF.RDB$Field_Position
INTO :tabla, :campo, posicion, :descripcion, :wtipo, :subtipo, :longitud,
:wprecision, :escala, :nulo
do begin
tipo= 'Desconocido';
if (wtipo = 261) Then
begin
if (subtipo = 1) Then
tipo='Texto BLOb';
else
tipo='BLOb';
end
if (wtipo = 14) Then tipo='Texto Char';
if (wtipo = 40) Then tipo='Texto CString';
if (wtipo = 11) Then tipo='Numérico D_Float';
if (wtipo = 27) Then tipo='Numérico Double' ;
if (wtipo = 10) Then tipo='Numérico Float' ;
if (wtipo = 16) Then
begin
if (subtipo = 1) Then tipo='Numérico';
if (subtipo = 2) Then
tipo='Decimal';
Else
tipo='Entero Int64';
End
if (wtipo = 8) Then
begin
if (subtipo = 1) Then tipo='Numérico';
if (subtipo = 2) Then tipo='Decimal'; Else tipo='Entero Integer';
End
if (wtipo = 9) Then tipo='Quad';
if (wtipo = 7 ) Then
begin
if (subtipo = 1) Then tipo='Numérico';
if (subtipo = 2) Then tipo='Decimal' ;Else tipo='Entero SmallInt';
End
if (wtipo = 12) Then tipo='Fecha Date';
if (wtipo = 13) Then tipo='Hora Time';
if (wtipo = 35) Then tipo='Fecha y hora TimeStamp';
if (wtipo= 37) Then tipo='Texto Varchar';
if (wtipo= 11) Then longitud= wPrecision;
if (wtipo= 27) Then longitud= wPrecision;
if (wtipo= 10) Then longitud= wPrecision;
if (wtipo= 16) Then
if (subtipo = 1 or subtipo =2) Then longitud= wPrecision;
if (wtipo= 8) Then
if (subtipo= 1 or subtipo=2) Then longitud= wPrecision;
if (wtipo= 7 ) Then
if (subtipo=1 or subtipo= 2) Then longitud= wPrecision;
if (escala = 0) Then DECIMALES= Null;
if (escala <> 0 and escala is not null) then DECIMALES= Cast (ESCALA * -1 As integer);
if (NULO = 1) Then PERMITE_NULOS= 'No'; Else PERMITE_NULOS= 'Si';
pk = null;
select i.rdb$field_position
from rdb$relation_constraints rc, rdb$index_segments i, rdb$indices idx
where (i.rdb$index_name = rc.rdb$index_name) and
(idx.rdb$index_name = rc.rdb$index_name) and
(rc.rdb$constraint_type = 'PRIMARY KEY') and
(rc.rdb$relation_name = :TABLA) and
(i.rdb$field_name = :CAMPO)
into :PK ;
if (pk is not null ) then pk = pk+1;
fk = null;
select 'FK: ' ||trim(D.RDB$FIELD_NAME)||' en Tabla '||trim(C.RDB$RELATION_NAME) FK
from RDB$REF_CONSTRAINTS B, RDB$RELATION_CONSTRAINTS A, RDB$RELATION_CONSTRAINTS C,
RDB$INDEX_SEGMENTS D, RDB$INDEX_SEGMENTS E, RDB$INDICES I
where (A.RDB$CONSTRAINT_TYPE = 'FOREIGN KEY') and
(A.RDB$CONSTRAINT_NAME = B.RDB$CONSTRAINT_NAME) and
(B.RDB$CONST_NAME_UQ=C.RDB$CONSTRAINT_NAME) and (C.RDB$INDEX_NAME=D.RDB$INDEX_NAME) and
(A.RDB$INDEX_NAME=E.RDB$INDEX_NAME) and
(A.RDB$INDEX_NAME=I.RDB$INDEX_NAME) and
(A.RDB$RELATION_NAME = :TABLA) and
(D.RDB$FIELD_NAME = :CAMPO)
into :FK;
suspend;
end
end