CoreCommand
DB2 useful SQL and commands
Catalog queries and operator commands worth knowing.
Catalog queries that answer real questions
-- columns of a table SELECT NAME, COLTYPE, LENGTH, SCALE, NULLS, COLNO FROM SYSIBM.SYSCOLUMNS WHERE TBNAME='ACCOUNT' ORDER BY COLNO; -- which packages depend on a table SELECT DISTINCT DCOLLID, DNAME FROM SYSIBM.SYSPACKDEP WHERE BNAME='ACCOUNT'; -- indexes and their columns SELECT I.NAME, K.COLNAME, K.COLSEQ, K.ORDERING FROM SYSIBM.SYSINDEXES I, SYSIBM.SYSKEYS K WHERE I.NAME=K.IXNAME AND I.TBNAME='ACCOUNT' ORDER BY I.NAME, K.COLSEQ; -- when were statistics last gathered? SELECT NAME, STATSTIME, CARDF FROM SYSIBM.SYSTABLES WHERE NAME='ACCOUNT';
Commands (authority required)
| Command | Does |
|---|---|
| -DIS THREAD(*) | Show active threads |
| -DIS DB(dbname) SPACENAM(*) RESTRICT | Show objects in a restricted state |
| -DIS UTIL(*) | Show running utilities |
| -START DB(dbname) | Start a database or table space |
| -TERM UTIL(name) | Terminate a stopped utility |
Stuck on something else?
Ask the community or search the full course.