What is CLUSTERED INDEX in DB2? Explain with the help of practical example.


In a CLUSTERED INDEX of a DB2 table, the data rows (table rows) with the similar index keys are stored in the same page. For example, If we have 4 index keys - T5623, T5611, Z9786 and Z9078. So the data rows with similar keys T5623 and T5611 will be stored in the same page and other similar keys Z9786 and Z9078 will be stored together on the other page.

The Clustered index structure has 2 types of pages i.e., Index page and data page. The index page stores all the index key values and points to the data page so that entire row data can be extracted. For example, if there is a table with Index key as a random whole number - 2, 5, 7, 12, etc. Then the clustered index structure would look like below−

The first 3 levels are the index pages having the value of index key. The third level of index pages points to the data pages. The clustered index is used when we need to access the table randomly.

Updated on: 14-Sep-2020

832 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements