Reputation: 473
Hi i'm trying to find column count for a db2 table. I have schema name and table name details. Tried with
select COUNT(*) from SYSCAT.COLUMNS WHERE TABNAME = 'ABC' and TABSCHEMA='XYZ'
AND
SELECT COUNT(*) FROM sys.columns WHERE object_id = OBJECT_ID('ABC')
But unfortunately both of them are throwing errors.
Need suggestions with my issue of finding column count for a table in db2 database
Upvotes: 0
Views: 3960
Reputation: 17492
this code work on system i (AS400...)
select * from qsys2.syscolumns
where COLUMN_NAME='YOURCOLUMNNAME'
and TABLE_NAME='YOURTABLENAME' and TABLE_SCHEMA='YOURLIB'
Upvotes: 0
Reputation: 473
Hi finally i was able to fix this issue by modifying my query to
select count(*) from sysibm.syscolumns where tbname = 'ABC' and TBCREATOR = 'XYZ'
where TBCREATOR is the schema name and tbname is the table name.
Upvotes: 1