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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.