Junior — Middle
How does a non-clustered index work in a database?
sobes.tech AI
Answer from AI
A non-clustered index in a database is a data structure that stores the values of the indexed column and references to the corresponding table rows, but does not alter the physical order of data storage.
Unlike a clustered index, where the table data is physically ordered by the index key, a non-clustered index is stored separately and contains pointers (such as addresses or keys) to the table rows.
Example:
- The data table is stored in arbitrary order.
- A non-clustered index is created on the "LastName" column.
- The index contains a sorted list of last names and references to the rows.
When searching by index, the DBMS first accesses the index, finds the necessary references, and then retrieves data from the table.