Hello Devz,

Today I had an issue with the performance of a SQL stored procedure. This procedure was supposed to delete a few millions rows in a table. But it was quite slow… So after optimizing the query, I looked at the database itself.

Having an indexed primary key is important but the level of fragmentation of the index is something important as well.

 

indexed primary key on sql table

indexed primary key on sql table

If you righ click on your index, and check the properties, then select Fragmentation, you can see the level of fragmentation of this index:

fragmentation level on an index in a sql table

fragmentation level on an index in a sql table

As you can see here the level of fragmentation is very important. All you have to do in that case it to Rebuild the index:

rebuild index of a fragmented primary key in sql table

rebuild index of a fragmented primary key in sql table

And now the performance will be way better…

defragmented index on a primary key of sql table

defragmented index on a primary key of sql table

Happy coding!  🙂