Ver Mensaje Individual
  #6  
Antiguo 01-01-2008
Avatar de fjcg02
[fjcg02] fjcg02 is offline
Miembro Premium
 
Registrado: dic 2003
Ubicación: Zamudio
Posts: 1.410
Reputación: 22
fjcg02 Va camino a la fama
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
  /* Procedure Text */
 for
  Select

RF.RDB$Relation_Name TABLA,  /* Nombre de la tabla/vista */
RF.RDB$Field_Name CAMPO,  /* Nombre del campo */
RF.RDB$Field_Position POSICION,  /* Posición del campo */
RF.RDB$Description DESCRIPCION,  /* Descripción del campo */
F.RDB$Field_Type,
F.RDB$Field_Sub_Type,
/* Tipo concreto */
F.RDB$Field_Length,
F.RDB$Field_Precision,
/* Decimales */
F.RDB$Field_Scale,
/* Permite o no valores nulos */
RF.RDB$Null_Flag

From RDB$Relation_Fields RF

/* La información de campos está distribuida en las tablas
RDB$Relation_Fields y RDB$Fields */
Left Join RDB$Fields F On RF.RDB$Field_Source = F.RDB$Field_Name

/* No incluir tablas del sistema */
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) /* BLOb */ 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) /* Integer */ 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 )/* SmallInt */ 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) /* D_Float */ Then longitud= wPrecision;
  if  (wtipo= 27) /* Double */ Then longitud= wPrecision;
  if  (wtipo= 10) /* Float */ Then longitud= wPrecision;
  if  (wtipo= 16) /* Int64 */ Then
    if (subtipo = 1 or subtipo =2) Then longitud= wPrecision;
  if  (wtipo= 8) /* Integer */ Then
      if (subtipo= 1 or subtipo=2) Then longitud= wPrecision;
  if  (wtipo= 7 )/* SmallInt */ Then
    if  (subtipo=1 or subtipo= 2) /* Decimal */ 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
__________________
Cuando los grillos cantan, es que es de noche - viejo proverbio chino -
Responder Con Cita