Chris wrote:
Can't seem to figure out how to do this and have been reading for some
time now......
I want to select a row count from a table name in SYSTABLES.
Don't use the SYSIBM.SYS* tables. They are not documented and, thus, not
supported.
This statement does not return what I needed, but can help explain what
I'm looking for. I want the results to be the Row Count from a Table
Name out of the Sub-Select.
Select Count(*) from
(Select SYSTEM_TABLE_NAME where SYSTEM_TABLE_NAME like ('MYTABLES%)
and
SYSTEM_TABLE_SCHEMA = 'MYSCHEMA')
Any help would be appreciated.
I don't quite understand what you want to do. Do you want to get the number
of tuples of all tables starting with the name MYTABLES in schema MYSCHEMA?
If so, your above query won't work, of course. The above query (even if it
would be syntactically correct and queries SYSCAT.TABLES), scans the
SYSCAT.TABLES view, filters out all rows that satisfy your search criteria
and then counts how many rows that were.
What you could do if you want to get the cardinality of the tables is to
query the CARD column in SYSCAT.TABLES:
SELECT tabname, card
FROM syscat.tables
WHERE tabname LIKE 'MYTABLES%' AND
tabschema = 'MYSCHEMA'
Note that CARD is population when you collect statistics on the respective
table. Thus, the value is not guaranteed to be correct if you didn't
collect statistics or if the stats are out of date.
If you want to count the rows in the tables (not relying on the statistics),
you will have to query those tables directly. For that, you can first scan
SYSCAT.TABLES to identify the qualifying tables, then construct a query
against each of the tables and execute those queries with dynamic SQL.
--
Knut Stolze
DB2 Information Integration Development
IBM Germany