Sometimes you'll need info about a table:
- in which tablespace does it reside?
- are there any views/triggers/etc defined?
- howmany rows?
- are all indexes really required by DB2?
So I created a "generate script SQL". You run this SQL, capture the output in a file and edit this file (prefix: db2 connect to .. & set current_schema/suffix: db2 connect reset) and save it as a script. When you execute this script (yeah, I know: long lines) the output will be a file for each table in your schema and that file will contain all kind of usefull (DBA)data about the table. The filename itself is also informative: the number of rows is part of the filename and if the file with the biggest size probably has the most DDL to carry around.
Code:
select varchar( 'db2look -d '
|| current_server
|| ' -t '
|| rtrim(name)
|| ' -e -p -o '
|| rtrim(lcase(name))
|| '.'
|| rtrim(char(bigint(card))) concat '.out'
|| ' && db2 -z '
|| rtrim(lcase(name))
|| '.'
|| rtrim(char(bigint(card))) concat '.out'
|| ' "describe table '
|| rtrim(current_schema)
|| '.'
|| rtrim(name)
|| ' "'
|| ' && db2 -z '
|| rtrim(lcase(name))
|| '.'
|| rtrim(char(bigint(card))) concat '.out'
|| ' "describe indexes for table '
|| rtrim(current_schema)
|| '.'
|| rtrim(name)
|| ' show detail"'
|| ' && db2pd -d '
|| rtrim(current_server)
|| ' -tcbstats all tbspaceid='
|| char(tid)
|| space(1)
|| 'tableid='
|| char(fid)
|| space(1)
|| 'file='
|| rtrim(lcase(name))
|| '.'
|| rtrim(char(bigint(card))) concat '.out'
|| ' && echo "Table '
|| rtrim(current_schema)
|| '.'
|| rtrim(name)
|| ', # of rows (according to latest RUNSTATS) :'
|| rtrim(char(bigint(card)))
|| '" >> '
|| rtrim(lcase(name))
|| '.'
|| rtrim(char(bigint(card))) concat '.out'
,768) as line
from sysibm.systables
where type = ucase('t')
and creator = current_schema
order by name
;
This version should be portable for all V8 & V9 versions of DB2 and on all platforms.
Please feel free to use it.