SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Index Fragmentation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Goldmember
Starting Member

USA
9 Posts

Posted - 06/22/2008 :  18:59:45  Show Profile  Reply with Quote
What functions of tools do you use for managing index fragmentation?

DBCC?

I am working through MS Press SQL 2005 book and it mentions the
sys.dm_db_index_physical_stats function? It then give an example of code which is very involved.

Does anybody use this function?

Thanks

rmiao
Flowing Fount of Yak Knowledge

USA
7266 Posts

Posted - 06/22/2008 :  19:24:14  Show Profile  Reply with Quote
You can use it or 'dbcc showcontig' to check index fragmentation.
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1765 Posts

Posted - 06/23/2008 :  01:43:09  Show Profile  Visit jackv's Homepage  Reply with Quote
The idea is that "sys.dm_db_index_physical_stats" will replace DBCC SHOWCONTIG .

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

Ola Hallengren
Starting Member

Sweden
33 Posts

Posted - 06/23/2008 :  13:27:16  Show Profile  Visit Ola Hallengren's Homepage  Reply with Quote
I have a stored procedure that is using sys.dm_db_index_physical_stats to decide if an index needs to be rebuilt or reorganized.
http://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html

Ola Hallengren
http://ola.hallengren.com

Edited by - Ola Hallengren on 03/03/2012 12:55:14
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 06/23/2008 :  13:29:49  Show Profile  Visit tkizer's Homepage  Reply with Quote
Here's my script: http://weblogs.sqlteam.com/tarad/archive/2007/11/27/60415.aspx

And here's all of my database maintenance routines: http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx

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

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 06/23/2008 :  13:30:41  Show Profile  Visit tkizer's Homepage  Reply with Quote
quote:
Originally posted by rmiao

You can use it or 'dbcc showcontig' to check index fragmentation.



From BOL:
quote:

Important:
This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use sys.dm_db_index_physical_stats instead.



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

Subscribe to my blog
Go to Top of Page

jeffdavid
Starting Member

8 Posts

Posted - 06/24/2008 :  10:14:59  Show Profile  Reply with Quote
hi, new to SQL Server. How do you determine whether to rebuild or reorganize indexes?
Go to Top of Page

Ola Hallengren
Starting Member

Sweden
33 Posts

Posted - 06/24/2008 :  10:41:27  Show Profile  Visit Ola Hallengren's Homepage  Reply with Quote
Read this article in Books Online.
http://msdn.microsoft.com/en-us/library/ms189858.aspx

You could use a script like Tara's or mine to do this dynamically.

Ola Hallengren
http://ola.hallengren.com

Edited by - Ola Hallengren on 06/24/2008 10:42:20
Go to Top of Page

jeffdavid
Starting Member

8 Posts

Posted - 06/24/2008 :  11:07:32  Show Profile  Reply with Quote
thanks!
Go to Top of Page

jeffdavid
Starting Member

8 Posts

Posted - 06/27/2008 :  10:04:21  Show Profile  Reply with Quote
Ola, Thank you so much. I read that article and it helped a lot. I was able to reorganize quite a few indexes. I reorganized the example query on that page to work for my database. However, upon running it, the results came back with some highly fragmented indexes, but null values in the name column. Is there another way to find out which indexes these are?
Go to Top of Page

Ola Hallengren
Starting Member

Sweden
33 Posts

Posted - 06/27/2008 :  13:53:09  Show Profile  Visit Ola Hallengren's Homepage  Reply with Quote
Index_id = 0 means that it's a heap (not an index)
Heaps have a NULL value in the name column in sys.indexes.

You can read about heaps here.
http://blogs.msdn.com/sqlserverstorageengine/archive/2006/09/19/761437.aspx

Ola Hallengren
http://ola.hallengren.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000