Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 avg_fragmentation_in_percent not updated

Author  Topic 

AgaK
Yak Posting Veteran

86 Posts

Posted - 2009-09-02 : 12:29:44
Hi

I am executing the following query to see the fragmentation of the indexes on my databases (SQL 2005):

SELECT
a.index_id,
b.name index_name,
a.avg_fragmentation_in_percent
FROM
sys.dm_db_index_physical_stats (66, NULL, NULL, NULL, NULL) AS a
JOIN
sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id
JOIN
sys.objects AS c ON c.object_id = a.object_id
JOIN
sys.schemas AS s ON s.schema_id = c.schema_id

WHERE (b.name IS NOT NULL) AND (a.avg_fragmentation_in_percent > 30)
ORDER BY a.avg_fragmentation_in_percent DESC

I am executing the following statement to rebuild the index on one of the tables:

ALTER INDEX ALL ON SchemaName.TableName REBUILD

When I run the select statement again the avg_fragmentation_in_percent values for indexes on SchemaName.TableName remain unchanged.

Any idea why? My understanding was that the value of avg_fragmentation_in_percent will get updated to 0 when the indexes are rebuilt.

Thank you kindly

AgaK

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-02 : 15:24:39
Depending upon the number of pages, you will not be able to get rid of fragmentation in some indexes. How many rows are there in your table?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

AgaK
Yak Posting Veteran

86 Posts

Posted - 2009-09-02 : 17:34:47
3510 rows in the table
Go to Top of Page

AgaK
Yak Posting Veteran

86 Posts

Posted - 2009-09-02 : 18:26:39
3510 rows and data space of 2.914 MB
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-02 : 19:00:57
It's probably too small to be defragmented.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

AgaK
Yak Posting Veteran

86 Posts

Posted - 2009-09-02 : 19:22:30
Thank you very much for you reply.

How big the table has to be to worry about defragmentation?

thank you again
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-02 : 19:35:39
It really depends on the number of pages. I believe 1000 pages or less cannot be defragmented. You probably have a "skinny" table, so not as many pages as there would be in a "wide" table with the same number of rows.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

AgaK
Yak Posting Veteran

86 Posts

Posted - 2009-09-03 : 11:12:26
Hi

Would you have any articles or web sites that you could recommand to me? on the sujbect?

Once again thank you
Go to Top of Page
   

- Advertisement -