July 21, 2009 at 10:16 am
Does somebody has a query to rebuild or reorganized (depending on the level of fragmentation) all the indexes in the database? The only input parameter is a database name.. It should find an indexes itself and make a decision what to do with it...
July 21, 2009 at 10:40 am
July 21, 2009 at 10:41 am
try this one out ..
July 21, 2009 at 11:04 am
Does somebody has a query to rebuild or reorganized (depending on the level of fragmentation) all the indexes in the database? The only input parameter is a database name.. It should find an indexes itself and make a decision what to do with it...
Hi,
Check the following link.It ll help u.
http://www.sqlservercentral.com/scripts/Administration/68802/
Muthukkumaran Kaliyamoorthy
https://www.sqlserverblogforum.com/
July 21, 2009 at 12:29 pm
Thanks so much!
Can I set
@frag >30 and pages 1000 then rebuild
@frag between 5 and 30 and pages 1000 then reorganize
Would it be correct?
July 21, 2009 at 3:15 pm
I use this package from MS's DB Operations team as part of my standard build. Have found them very reliable and extendible.
http://download.microsoft.com/download/4/0/C/40CBAD9A-D990-450B-8785-F288CEBFB448/AITScripts.zip
July 21, 2009 at 5:16 pm
Heh... don't over look what's in Books Online. If you lookup "DBCC SHOWCONTIG" and scroll down, you'll find a section with the following label...
[font="Arial Black"]E. Using DBCC SHOWCONTIG and DBCC INDEXDEFRAG to defragment the indexes in a database[/font]
That section has the very code you seek in it. 😉 And, yes, it has a cursor in it... it's one of the very few places where a cursor might actually be condoned.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 22, 2009 at 8:15 pm
As per MS U r correct.
Thanks so much!
Can I set
case 1:@frag >30 and pages 1000 then rebuild
case 2:@frag between 5 and 30 and pages 1000 then reorganize
Would it be correct?
Hi Vika,
U can use .Its depends.
If u get any error replay me.
e.g
case 2:If Allow page lock=OFF in this case the job was failed and u will get following error.
Msg 2552, Level 16, State 2, Line 1
The index "CIX (partition 1) on table "table_name" cannot be reorganized because page level locking is disabled.
Edit :add more info
Muthukkumaran Kaliyamoorthy
https://www.sqlserverblogforum.com/
July 23, 2009 at 8:29 am
Jeff Moden (7/21/2009)
Heh... don't over look what's in Books Online. If you lookup "DBCC SHOWCONTIG" and scroll down, you'll find a section with the following label...[font="Arial Black"]E. Using DBCC SHOWCONTIG and DBCC INDEXDEFRAG to defragment the indexes in a database[/font]
That section has the very code you seek in it. 😉 And, yes, it has a cursor in it... it's one of the very few places where a cursor might actually be condoned.
Jeff
It's interesting that in that very same topic, Microsoft says "This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work" and "Use ALTER INDEX…REORGANIZE to reorder the leaf-level pages of the index in a logical order", and then it proceeds to use the old code in its examples!
John
July 23, 2009 at 8:38 am
The code that is recommended for SQL 2005 can be found in books on line under 'sys.dm_db_index_physical_stats' .
It is very similar to the code in "DBCC SHOWCONTIG" page
July 23, 2009 at 1:05 pm
John Mitchell (7/23/2009)
Jeff Moden (7/21/2009)
Heh... don't over look what's in Books Online. If you lookup "DBCC SHOWCONTIG" and scroll down, you'll find a section with the following label...[font="Arial Black"]E. Using DBCC SHOWCONTIG and DBCC INDEXDEFRAG to defragment the indexes in a database[/font]
That section has the very code you seek in it. 😉 And, yes, it has a cursor in it... it's one of the very few places where a cursor might actually be condoned.
Jeff
It's interesting that in that very same topic, Microsoft says "This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work" and "Use ALTER INDEX…REORGANIZE to reorder the leaf-level pages of the index in a logical order", and then it proceeds to use the old code in its examples!
John
Heh... true enough on both points. I tend to make things as backwards compatible to 2k as possible because I saw a survey (again, recently) that says that more than 67% of all IT shops still have SQL Server 2k instances running. It also shows that I really need to install the Dev Edition of 2k8 on my machine so I can catch these caveats as the product progresses.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply