Posted - 06/17/2010 : 08:27:06
| Hi all, I am currently working on some code that will allow me to set-up a nightly task that checks the indexes of a particular Db and then emails the results to me.
Now the code I have already does seem to work, but it does not give the reults of the specified DB, it always sends the same results no matter what DB i use.
What am I doing wrong?, here is my code.
USE Database Name Goes Here
@profile_name = 'Administrator',
@recipients = 'My Email',
@subject = 'Fragmentation Results',
@query = 'SELECT OBJECT_NAME(i.OBJECT_ID) AS TableName, i.name AS IndexName,indexstats.avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, ''DETAILED'') indexstats INNER JOIN sys.indexes i ON i.OBJECT_ID = indexstats.OBJECT_ID AND i.index_id = indexstats.index_id WHERE indexstats.avg_fragmentation_in_percent > 20'