From the course: Developing Microsoft SQL Server 2016 Databases
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Defragment indexes - SQL Server Tutorial
From the course: Developing Microsoft SQL Server 2016 Databases
Defragment indexes
- [Instructor] Over time, as records get added and removed from a table, the indexes built on those tables will begin to get fragmented. This means that the information is scattered across physical pages that are not in the same order as the logical records based on their key values. Having fragmented indexes cause queries to perform slower, and that's never something that you'd want. To remedy this, you'll simply need to defragment the index. This will reorganize the leaf nodes within each page back into logical order, and then rebuild the index so that it matches the physical data file. To take a look at this, I'm going to use the wide world importers database, so I'll go ahead and highlight lines two and three and execute them. Then, I want to see what fragmentation exists on a particular table. We can see the tables by expanding the databases folder, and then opening up the wide world importers database, expanding tables,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.