Wednesday, July 02, 2008

Figuring out which column nulls are being inserted into ....

Actually see this kind of error a lot at work:

DB2 SQL error: SQLCODE: -407, SQLSTATE: 23502, SQLERRMC: TBSPACEID=2, TABLEID=1301, COLNO=0

If you see this error, you can just run the following sql to find out which table and column the null was being inserted into:

SELECT C.TABSCHEMA, C.TABNAME,
C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = n1
AND T.TABLEID = n2
AND C.COLNO = n3
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME

where the values from the error are replaced for n1, n2 and n3. This is actually from the DB2 V9.5 docs.

No comments: