7.9. Indexes

Indexes are database objects that are built based on one or more columns of a table. They are used for two main reasons:

  • To improve query performance because they can access the data faster with direct access to rows based on their key values

  • To guarantee uniqueness when defined as unique

7.9.1. Working with Indexes

To create an index, use the CREATE INDEX statement. This statement requires at a minimum:

  • The name of the index

  • The name of the associated table

  • The columns that make up the index (also known as index keys)

In addition, you can specify the following:

  • Whether the index is unique (enforce uniqueness for the key values) or non-unique (allow duplicates)

  • Which order DB2 should use to build and maintain the key values: ascending ...

Get Understanding DB2®: Learning Visually with Examples now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.