[firebase-br] SQl Complexo
Rodrigo Rodrigues
dodomr.fb em gmail.com
Sex Ago 22 09:42:37 -03 2008
Esse sql abaixo, mostra os campos da tabela, alem das chaves, e relacao,
chave x tabela, não to conseguindo fazer com que apenas uma vez apareça o
nome do campo... se alguem puder ajudar.
SELECT distinct CAMPOS.RDB$FIELD_NAME AS COLUMN_NAME,
CAMPOS.RDB$DESCRIPTION AS DESCRICAO,
DADOSCAMPO.RDB$FIELD_LENGTH AS TAMANHO,
CAMPOS.RDB$FIELD_SOURCE AS NOME_INTERNO,
CASE
DADOSCAMPO.RDB$FIELD_TYPE
WHEN 7 THEN 'SMALLINT'
WHEN 8 THEN 'INTEIRO'
WHEN 16 THEN 'NUMÉRICO'
WHEN 10 THEN 'FLOAT'
WHEN 27 THEN 'DOUBLE PRECISION'
WHEN 12 THEN 'DATA'
WHEN 13 THEN 'TEMPO'
WHEN 35 THEN 'TEMPO STAMP'
WHEN 14 THEN 'CHAR'
WHEN 37 THEN 'VARCHAR-TEXTO'
WHEN 261 THEN 'BLOB' ELSE 'TIPO DESCONHECIDO ' || DADOSCAMPO.RDB$FIELD_TYPE
END AS TIPO_DE_CAMPO,
CASE
WHEN DADOSCAMPO.RDB$FIELD_TYPE IN(16,8) THEN DADOSCAMPO.RDB$FIELD_PRECISION
ELSE DADOSCAMPO.RDB$FIELD_LENGTH
END AS PRECISAO,
CASE
CAMPOS.RDB$NULL_FLAG
WHEN 1 THEN 'N' ELSE 'Y'
END AS NULO,
DADOSCAMPO.RDB$FIELD_TYPE AS NR_TIPO,
DADOSCAMPO.RDB$FIELD_PRECISION AS PRECISAO,
RC.RDB$CONSTRAINT_NAME ,
CASE
RC.RDB$CONSTRAINT_TYPE
WHEN 'PRIMARY KEY' THEN 'PRIMARIA'
WHEN 'FOREIGN KEY' THEN 'ESTRANGEIRA'
END AS TIPO,
I2.RDB$RELATION_NAME,
S.RDB$FIELD_NAME,
S2.RDB$FIELD_NAME, count(*)
FROM
RDB$RELATIONS TABELAS,
RDB$RELATION_FIELDS CAMPOS,
RDB$FIELDS DADOSCAMPO,
RDB$TYPES TIPOS,
RDB$INDEX_SEGMENTS S
LEFT JOIN RDB$INDICES I ON I.RDB$INDEX_NAME = S.RDB$INDEX_NAME
LEFT JOIN RDB$RELATION_CONSTRAINTS RC ON RC.RDB$INDEX_NAME =
S.RDB$INDEX_NAME
LEFT JOIN RDB$REF_CONSTRAINTS REFC ON RC.RDB$CONSTRAINT_NAME =
REFC.RDB$CONSTRAINT_NAME
LEFT JOIN RDB$RELATION_CONSTRAINTS RC2 ON RC2.RDB$CONSTRAINT_NAME =
REFC.RDB$CONST_NAME_UQ
LEFT JOIN RDB$INDICES I2 ON I2.RDB$INDEX_NAME = RC2.RDB$INDEX_NAME
LEFT JOIN RDB$INDEX_SEGMENTS S2 ON I2.RDB$INDEX_NAME =
S2.RDB$INDEX_NAME
WHERE
TABELAS.RDB$RELATION_NAME = 'MINHA_TABELA'
AND TIPOS.RDB$FIELD_NAME = 'RDB$FIELD_TYPE'
AND TABELAS.RDB$RELATION_NAME = CAMPOS.RDB$RELATION_NAME
AND CAMPOS.RDB$FIELD_SOURCE = DADOSCAMPO.RDB$FIELD_NAME
AND DADOSCAMPO.RDB$FIELD_TYPE = TIPOS.RDB$TYPE
AND DADOSCAMPO.RDB$SYSTEM_FLAG=0
and I.RDB$RELATION_NAME='TB_PESSOA_EMAIL'
AND RC.RDB$CONSTRAINT_TYPE IS NOT NULL
GROUP by CAMPOS.RDB$FIELD_NAME ,
CAMPOS.RDB$DESCRIPTION ,
DADOSCAMPO.RDB$FIELD_LENGTH ,
CAMPOS.RDB$FIELD_SOURCE ,
CASE
DADOSCAMPO.RDB$FIELD_TYPE
WHEN 7 THEN 'SMALLINT'
WHEN 8 THEN 'INTEIRO'
WHEN 16 THEN 'NUMÉRICO'
WHEN 10 THEN 'FLOAT'
WHEN 27 THEN 'DOUBLE PRECISION'
WHEN 12 THEN 'DATA'
WHEN 13 THEN 'TEMPO'
WHEN 35 THEN 'TEMPO STAMP'
WHEN 14 THEN 'CHAR'
WHEN 37 THEN 'VARCHAR-TEXTO'
WHEN 261 THEN 'BLOB' ELSE 'TIPO DESCONHECIDO ' || DADOSCAMPO.RDB$FIELD_TYPE
END ,
CASE
WHEN DADOSCAMPO.RDB$FIELD_TYPE IN(16,8) THEN DADOSCAMPO.RDB$FIELD_PRECISION
ELSE DADOSCAMPO.RDB$FIELD_LENGTH
END ,
CASE
CAMPOS.RDB$NULL_FLAG
WHEN 1 THEN 'N' ELSE 'Y'
END ,
DADOSCAMPO.RDB$FIELD_TYPE ,
DADOSCAMPO.RDB$FIELD_PRECISION,
RC.RDB$CONSTRAINT_NAME ,
CASE
RC.RDB$CONSTRAINT_TYPE
WHEN 'PRIMARY KEY' THEN 'PRIMARIA'
WHEN 'FOREIGN KEY' THEN 'ESTRANGEIRA'
END ,
I2.RDB$RELATION_NAME,
S.RDB$FIELD_NAME,
S2.RDB$FIELD_NAME
--ORDER BY CAMPOS.RDB$FIELD_POSITION
Mais detalhes sobre a lista de discussão lista