Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does inserting/updating/deleting record auto update indexes?

Does inserting/ updating or deleting a record in DB auto update the indexes?

I've seen rebuild commands for indexes and I just can't understand if I have to do all these manually, then what's the purpose of indexes. This is so inconvenient that I spend time rebuilding the indexes every week or so.

like image 778
Jack Avatar asked Dec 27 '22 07:12

Jack


2 Answers

When index fragmentation becomes too high, indexes will be very inefficient. There is need to rebuild index.

Let SQL Server Tell You Which Indexes to Rebuild

Rebuilding an index drops and re-creates the index. This removes fragmentation, reclaims disk space by compacting the pages based on the existing fill factor setting, and reorders the index rows in contiguous pages.

Reorganizing and Rebuilding Indexes

like image 177
Pranay Rana Avatar answered Jan 13 '23 13:01

Pranay Rana


Yes, when you insert, update, or delete a row, any indexes on that table automatically reflect the change.

like image 35
Tim Avatar answered Jan 13 '23 11:01

Tim