views:

157

answers:

2

I have a simple little table (just 8 fields) an hour ago I rebuilt one of the indexes on the table, which reset it to 0% fragmentation, but now it’s up to 38%.

The table itself has 400k records in it, but only 158 new ones have been inserted since I rebuilt the index, there have been no updates to records but perhaps a couple of deletes.

Why should the index be getting so fragmented?

The index is non-unique, non-clustered just on one field.

The database is running on SQL Server 2005 but with a compatibility level of SQL Server 2000.

Thanks

+3  A: 

Check the Fill Factor for that index when it is re-built. The fill factor may be too high. If this is the case, the index pages will be too full when the index is re-built and adding new rows will soon start to cause page splits (fragmentation). Reducing the fill factor on rebuild will allow more new records to be inserted into the index pages before page splitting starts to occur.

http://msdn.microsoft.com/en-us/library/aa933139%28SQL.80%29.aspx

NYSystemsAnalyst
Thanks for your answer. When I rebuilt the index I set the fill factor to zero, which is what it is set to in sys.indexes?!?
Iain Hoult
Don't use a fill factor of 0. I thought the default is normally 80 or something like that ... not sure. You could set it to 50 or 60...?
NYSystemsAnalyst
+2  A: 

Fill factor 0 is equal to 100, so you are not allowing any room for inserts. You should be choosing a lower fill factor if you will be inserting.

Sam
Reducing the fill factor would put space between the index rows in a page, but would new table rows result in new index rows going into those gaps or being added at the end?
Iain Hoult
It fills in the gaps. If the fill factor is 100, then the pages are completely filled and there is no room for newly inserted rows. Therefore, those rows get put onto new pages (a.k.a. a page split).
NYSystemsAnalyst