CREATE TABLE is more than a column list. After keys and data types, DB2 for z/OS lets you set how rows are stored, how the optimizer treats the table, and how much the log and SMF hear about changes. This page covers COMPRESS, partitioning, hash organization, volatile tables, APPEND, DATA CAPTURE, and AUDIT.
Column definitions answer “what is a row?” These clauses answer “how should Db2 lay rows down, find them, and record that someone changed them?” Getting them wrong does not always fail CREATE TABLE—it fails six months later as CPU, clustering, or a replication gap.
| Option | Effect |
|---|---|
| COMPRESS | Store rows compressed on the page set |
| PARTITION BY | Range (PBR) or growth-related partitioning of the table |
| Hash organization | Place rows by hash of a unique key |
| VOLATILE | Prefer index access in optimization |
| APPEND | Insert at end rather than clustering search |
| DATA CAPTURE | NONE vs CHANGES extra log data |
| AUDIT | NONE, CHANGES, or ALL access auditing |
COMPRESS YES stores rows in a compressed form on disk, using a dictionary (and, on recent releases, optional Huffman / fixed-length algorithms: COMPRESS YES HUFFMAN or FIXEDLENGTH on the table space). You usually set compression on CREATE TABLESPACE. When CREATE TABLE implicitly creates a PBG space, a table-level COMPRESS clause can apply to that space.
1234567891011CREATE TABLESPACE ORDTS IN ORDDB MAXPARTITIONS 8 SEGSIZE 32 COMPRESS YES; CREATE TABLE ORD.ORDERS ( ORDNO INTEGER NOT NULL, ... ) IN ORDDB.ORDTS;
Table-level PARTITION BY is how a PBR table declares key ranges. Each PARTITION n ENDING AT (value) sets the high key for that part. MAXVALUE is the last part. Columns in the partition key are usually leading columns of a partitioned index.
123456789101112CREATE TABLE APP.ACTIVITY ( CUSTNO INTEGER NOT NULL, LAST_ACTIVITY DATE, COL2 CHAR(10), CONSTRAINT PK_ACT PRIMARY KEY (CUSTNO) ) IN DBB.TS01 PARTITION BY RANGE (CUSTNO) (PARTITION 1 ENDING AT (999), PARTITION 2 ENDING AT (1999), PARTITION 3 ENDING AT (2999), PARTITION 4 ENDING AT (MAXVALUE));
Without a range key, implicit or explicit PBG partitioning grows by size instead of by key. ALTER PARTITION / ROTATE PARTITION apply to range-partitioned tables, not to PBG. Choose the partitioning key for utilities (REORG PART, COPY PART) and for query pruning, not only for “it looks neat.”
Hash organization places a row by hashing a unique hash key into a preallocated HASH SPACE, aiming for roughly one GETPAGE to fetch by that key. Syntax families you will see include ORGANIZE BY HASH and HASH SPACE on CREATE TABLE (exact clause names follow your SQL Reference). Requirements typically include a unique hash key and a fixed hash space size.
Hash shines for random singleton lookups. It can lose to a clustering index plus sequential detection when a batch file of keys is sorted into cluster order. Hash is not the default for new OLTP tables in most shops; treat it as a measured exception. Some later Db2 directions de-emphasise hash versus UTS + good indexes—check your version’s restrictions before designing a new hash table.
VOLATILE (as opposed to NOT VOLATILE) tells the optimizer that cardinality is unstable or that index access should be preferred whenever possible. RUNSTATS might say “tiny table, scan it”; VOLATILE says “still use the index.” Typical use: small reference tables that spike, or tables you must not tablespace-scan.
123456789CREATE TABLE APP.CODETAB ( CODE CHAR(4) NOT NULL PRIMARY KEY, DESCR VARCHAR(40) NOT NULL ) IN APPDB.CDTS VOLATILE; ALTER TABLE APP.CODETAB VOLATILE; ALTER TABLE APP.CODETAB NOT VOLATILE;
VOLATILE is not the same as a created global temporary table or a volatile table in other database products. The data is still persistent; only optimization bias changes.
APPEND YES skips the search for a page that preserves clustering. Db2 appends inserted (and loaded) rows toward the end of the table space. Inserts can be cheaper and more concurrent; the clustering index becomes less representative until you REORG. APPEND NO (default) tries to insert near the cluster-key neighbours.
Use APPEND YES for high-volume insert tables that you REORG regularly, or when clustering is irrelevant. Do not combine it with a hope that range scans on the cluster key stay perfectly sequential without maintenance.
1ALTER TABLE APP.EVENT_LOG APPEND YES;
DATA CAPTURE NONE (default) logs the usual undo/redo information. DATA CAPTURE CHANGES logs extra details so capture programs (SQL replication, IBM InfoSphere CDC, and similar) can reconstruct full row images without always hitting the table. Cost is more log volume. Catalog tables have special rules; DATA CAPTURE CHANGES may be the only ALTER allowed on some catalog tables.
If RESTRICT_ALT_COL_FOR_DCC is YES, some column ALTERs are blocked while DATA CAPTURE CHANGES is on. Plan replication requirements before you freeze the table in that mode.
AUDIT controls whether Db2 writes audit trace/SMF information for the table:
Auditing is a compliance switch, not a substitute for RACF. It can generate significant SMF. Turn it on for sensitive tables with a plan to collect and retain the records.
1234567CREATE TABLE SEC.PAYROLL ( EMPNO CHAR(6) NOT NULL PRIMARY KEY, SALARY DECIMAL(9,2) ) IN SECDB.PAYTS AUDIT CHANGES DATA CAPTURE CHANGES;
A high-insert event table might be PBG, APPEND YES, COMPRESS YES, AUDIT NONE, DATA CAPTURE NONE. A parent customer table might be PBR on CUSTNO, APPEND NO, VOLATILE NO, DATA CAPTURE CHANGES if it is replicated, AUDIT CHANGES if privacy rules require it. Hash organization would only appear if measurements beat a unique clustering index for that access pattern.
COMPRESS is stuffing winter coats into vacuum bags so the closet holds more. Partitioning is giving each grade its own classroom so you can clean one room without closing the school. Hash organization is putting each backpack on the hook whose number you get by mixing up the nametag—fast if you know the nametag, messy if you wanted them in ABC order. VOLATILE is telling the librarian “always use the card catalog, even if the shelf looks small.” APPEND is tossing new books on the end of the shelf instead of sliding them into ABC order. DATA CAPTURE is keeping a carbon copy of every change for someone down the hall. AUDIT is the hall monitor writing down who opened the closet.
Beyond columns and keys: COMPRESS, PARTITION BY (range or size/growth), hash organization (ORGANIZE BY HASH / HASH SPACE), VOLATILE, APPEND, DATA CAPTURE, and AUDIT. These change storage, access paths, logging, and compliance—not the column list.
Compression is primarily a table space attribute (COMPRESS YES on CREATE TABLESPACE). CREATE TABLE can specify COMPRESS when the table space is created implicitly. Adaptive (Huffman) vs fixed-length compression depends on your Db2 version and COMPRESS YES HUFFMAN / FIXEDLENGTH options.
Small tables whose size fluctuates, or tables you never want scanned, such as code tables that sometimes look large to a stale RUNSTATS. VOLATILE tells the optimizer to prefer index access. Do not stamp it on huge fact tables.
Rows are placed by hashing a unique key into a hash space instead of clustering by index order. Point lookups by that key can need fewer GETPAGEs. Sequential batch that follows a cluster key may be worse. Hash-organized tables are a specialised design; many shops stay with clustering indexes.
DATA CAPTURE CHANGES enriches the Db2 log for replication. AUDIT NONE/CHANGES/ALL produces audit records (SMF) about who touched the table. You can need both, neither, or one of them.
1. What does APPEND YES do on a Db2 table?
2. VOLATILE on a table means:
3. DATA CAPTURE CHANGES is used mainly for:
4. PARTITION BY RANGE on CREATE TABLE creates:
5. AUDIT CHANGES records: