How, What, and Why to Index

Indexes speed the retrieval of data. An index on a column can often make the difference between a nearly immediate response to a query and a long wait.

So why not index every column? The most significant reason is that building and maintaining an index takes time and storage space on the database device.

A second reason is that inserting, deleting, or updating data in indexed columns takes a little longer than in unindexed columns because of the time it takes the system to maintain the index when key values are changed. However, this cost is usually outweighed by the extent to which indexes improve retrieval performance.

In general, it's usually appropriate to put indexes on columns you use frequently in retrievals, ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition 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.