26 min read
Indexing
An index is a separate lookup structure the DBMS keeps so it does not have to read every row to find a phone number.
Finding one row in a large table
A small Members table is easy to read from top to bottom. Six rows. Sophie is obvious.
A working library is not six rows. It may be thousands of members. If staff ask "who has 07700 900 123?", the software's basic method is to start at row 1 and keep going until it finds a match. That is a table scan: read every row, just in case.
You already know a better tool in ordinary life. A book's index does not ask you to read every page to find "irrigation". It keeps a sorted list of topics and the pages they appear on.
A database index is the same idea. The DBMS keeps a separate, ordered lookup for a column — Phone, for example — and uses it to jump to matching rows instead of walking the whole table.
Table scan versus index lookup
A separate DBMS structure
The Members table stores names, cities, and phones. The index is another structure — maintained by the DBMS, not typed by staff.
It holds phone values in order, each pointing at the MemberID of the matching row. When staff search by phone, the software walks the index, not every full member record.
| Index on Phone (separate from Members) | |
|---|---|
| Members | |||
|---|---|---|---|
Benefits and costs
Two jobs
| Helps | Costs |
|---|---|
| Finding a member by phone | Each new or changed phone must update the Phone index |
| Sorting titles A–Z quickly | An index on a rarely searched column is wasted work |
| Joining on MemberID | Primary keys are already indexed automatically |
Primary keys are indexed automatically in the systems you will meet, including Microsoft Access. MemberID already has an index.
Add extra indexes on columns you search or sort often: Phone, Title, perhaps City if staff often filter by city.
Do not index every column. Each index is a second structure updated on every insert, change, or delete. Too many indexes make writing slower even as reading gets faster.
Practice
Swipe or use the arrows to move between questions.
1 / 3
Section check
Before you continue: queries and indexes
Queries read current tables. Indexes help the DBMS find rows without a table scan.
This is practice, not the final assessment. Use hints. Look up a lesson if you are unsure — there is no score.
Self-check
Self-check
Select every move used.
Self-check
Self-check
More lessons in Database Fundamentals · Next: Putting It Together · Previous: Asking Questions of Data
