maravilloso
6/12/2013 - 5:54 AM

Obtener nombre y código de tipo de todas las columnas de la base de datos (obviando las de sistema)

Obtener nombre y código de tipo de todas las columnas de la base de datos (obviando las de sistema)

0 = CHAR
1 = SMALLINT
2 = INTEGER
3 = FLOAT
4 = SMALLFLOAT
5 = DECIMAL
6 = SERIAL *
7 = DATE
8 = MONEY
9 = NULL
10 = DATETIME
11 = BYTE
12 = TEXT
13 = VARCHAR
14 = INTERVAL
15 = NCHAR
16 = NVARCHAR
17 = INT8
18 = SERIAL8 1
19 = SET
20 = MULTISET
21 = LIST
22 = ROW (unnamed)
23 = COLLECTION
40 = Variable-length opaque type 2
41 = Fixed-length opaque type 2
43 = LVARCHAR (client-side only)
45 = BOOLEAN
52 = BIGINT
53 = BIGSERIAL

Según:
http://publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.sqlr.doc/ids_sqr_025.htm
SELECT
    CAST(t.tabname AS VARCHAR(15)) AS tabla,
    CAST(colname AS VARCHAR(15)) AS campo,
    CASE
        WHEN coltype >= 256 THEN cast(coltype-256 AS VARCHAR(4))
        ELSE cast(coltype AS VARCHAR(4))
    END AS tipo,
    collength AS lon
FROM syscolumns c, systables t
WHERE c.tabid=t.tabid AND t.tabname[1,2]='fa'
ORDER BY 1, 2