From the course: Designing Database Solutions for SQL Server 2016

Unlock the full course today

Join today to access over 23,300 courses taught by industry experts.

Repair fragmented indexes

Repair fragmented indexes

- [Instructor] When records get added and removed from a table, the indexes built on a table columns 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 causes queries to perform slower and that's never something that you'd want. To remedy this you just simply need to defragment the index. This will reorganize the sequencing of the indexes nodes back into a logical order, and then rebuild the index so that it matches the physical data file. Lets take a look at how this works by creating a new database, I'll call mine fragmented DB. Then I need to table this database so I'll create one called dbo.products, you'll just have a product ID as the identity primary key field and the product name. Next we'll create an index on the product name field in the product's table, and finally we're going to add some records into this table. Now I need…

Contents