- DB2 Tutorial
- Home
- DB2 - Introduction
- DB2 - Server Installation
- DB2 - Instance
- DB2 - Databases
- DB2 - Bufferpools
- DB2 - Tablespaces
- DB2 - Storagegroups
- DB2 - Schemas
- DB2 - Data Types
- DB2 - Tables
- DB2 - Alias
- DB2 - Constraints
- DB2 - Indexes
- DB2 - Triggers
- DB2 - Sequences
- DB2 - Views
- DB2 with XML
- DB2 - Backup and Recovery
- DB2 - Database Security
- DB2 - Roles
- DB2 - LDAP
- DB2 Useful Resources
- DB2 - Questions and Answers
- DB2 - Quick Guide
- DB2 - Useful Resources
- DB2 - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DB2 - Indexes
This chapter covers introduction to indexes, their types, creation and dropping.
Introduction
Index is a set of pointers, which can refer to rows in a table, blocks in MDC or ITC tables, XML data in an XML storage object that are logically ordered by the values of one or more keys. It is created on DB2 table columns to speed up the data access for the queries, and to cluster and partition the data efficiently. It can also improve the performance of operation on the view. A table with a unique index can have rows with unique keys. Depending on the table requirements, you can take different types of indexes.
Types of indexes
- Unique and Non-Unique indexes
- Clustered and non-clustered indexes
Creating indexes
For creating unique indexes, you use following syntax:
Syntax:
db2 create unique index <index_name> on <table_name>(<unique_column>) include (<column_names..>)
Example: To create index for “shopper.sales1” table.
db2 create unique index sales1_indx on shopper.sales1(id) include (itemname)
Dropping indexes
For dropping the index, you use the following syntax:
Syntax:
db2 drop unique index <index_name> on <table_name>(<unique_column>) include (<column_names..>)
Example:
db2 drop index sales_index