Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @indexQuery nvarchar(1000)
- select @indexQuery = 'USE [MyDB]; SELECT i.index_id, i.name, s.avg_fragmentation_in_percent
- FROM sys.dm_db_index_physical_stats (
- DB_ID(),
- OBJECT_ID(N''MyTable''),
- DEFAULT, DEFAULT, DEFAULT) s, sys.indexes i
- WHERE s.object_id = i.object_id
- AND s.index_id = i.index_id;'
- exec msdb.dbo.sp_send_dbmail @profile_name='Local Mail Profile', @recipients='someone@somewhere.co.uk', @subject='Re-index Started', @query = @indexQuery, @attach_query_result_as_file=1, @query_attachment_filename = 'Reindex BEFORE.txt'
- select @indexQuery = 'indexoptimize ''MyDB'''
Add Comment
Please, Sign In to add comment