Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
🗃 DB2

DB2 Indexes

Intermediate 🕑 12 min read 👁 0 views

12

Code Example


## DB2 Indexes

Indexes improve query performance by providing fast access paths.

### Create Index
\`\`\`sql
CREATE INDEX index-name
ON table-name (column [ASC|DESC], ...)
\`\`\`

### Index Types

| Type | Description |
|------|-------------|
| Unique | No duplicate keys |
| Non-unique | Allows duplicates |
| Clustering | Determines physical order |
| Partitioned | Matches table partitions |

### When to Create Indexes

1. Primary key (automatic)
2. Foreign key columns
3. Frequently searched columns
4. JOIN columns
5. ORDER BY columns

### When NOT to Index

1. Small tables
2. Frequently updated columns
3. Low cardinality columns
4. Columns rarely in WHERE

### Index Maintenance
Indexes need REORG when fragmented.