Author |
Topic |
guaro5555
Starting Member
16 Posts |
Posted - 2013-03-14 : 08:30:26
|
Hi I am new to Sql admin so go easy on me ,but I would like if possible for someone to share a good script to check fragmentation on a database to let me know in what shape it is.Thanks a bunch gurus |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2013-03-14 : 10:27:18
|
[code]declare @db intset @db = db_id()SELECT object_name(s.object_id), i.name, i.type_desc, index_depth, avg_fragmentation_in_percent, fragment_count, page_countFROM sys.dm_db_index_physical_stats (@db, null, NULL, NULL, NULL) sjoin sys.indexes ion i.object_id = s.object_idAnd i.index_id = s.index_idJOIN sys.partitions pOn p.object_id = s.object_idAnd p.partition_number = s.partition_numberAnd p.index_id = s.index_idwhere avg_fragmentation_in_percent > 29--and p.rows > 9999--and index_depth > 2[/code] |
|
|
guaro5555
Starting Member
16 Posts |
Posted - 2013-03-14 : 11:06:51
|
R thanks for jumping inI know i might get some heat for my ignorance but which parameter do I have to change to enter the database name .that will be query for this information on this scriptagain thanks a bunch for your help and patience |
|
|
guaro5555
Starting Member
16 Posts |
Posted - 2013-03-14 : 11:07:56
|
using like "test" as a database name example |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2013-03-14 : 11:22:16
|
The query I posted does it for the current database.USE test;then the rest of the script |
|
|
guaro5555
Starting Member
16 Posts |
Posted - 2013-03-14 : 11:25:45
|
Thankssss a BUNCHHHH chief |
|
|
guaro5555
Starting Member
16 Posts |
Posted - 2013-03-14 : 11:27:44
|
R one last question and thanks againwhat does this do--and p.rows > 9999--and index_depth > 2Thanks |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2013-03-14 : 12:13:31
|
If you un-comment those two lines it will filter out small indexes that won't likely benefit from being rebuilt or defragmented. |
|
|
guaro5555
Starting Member
16 Posts |
Posted - 2013-03-14 : 13:50:34
|
YOU the GURU thanks abunch |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2013-03-14 : 21:14:37
|
Welcome Glad to help |
|
|
|