Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

A place to share commonly used scripts for SQL Server Database Administrators.

Moderators

SQL Server DBA Scripts

When was Index Maintenance (rebuild/reorganize) last performed on your database?

Jul 15 2012 12:00AM by Nakul Vachhrajani   

Have you ever wondered when your index was last rebuilt/reorganized? Here are two versions - using the Catalog view sys.indexes that would help you to identify the last date/time when the index statistics were updated, the number & percentage of rows changed during the last operation and the associated index name.

--Option #01:
USE AdventureWorks2008R2
GO
SELECT name AS index_name,
       STATS_DATE(object_id, index_id) AS statistics_update_date
FROM sys.indexes
WHERE object_id = OBJECT_ID('HumanResources.Employee');
GO


--Option 02:
USE AdventureWorks2008R2
GO
SELECT   ss.name AS SchemaName,
         st.name AS TableName,
         s.name AS IndexName,
         STATS_DATE(s.id, s.indid) AS 'Statistics Last Updated',
         s.rowcnt AS 'Row Count',
         s.rowmodctr AS 'Number Of Changes',
         CASE WHEN s.rowmodctr > 0 
              THEN CAST ((CAST (s.rowmodctr AS DECIMAL (28, 8)) / CAST (s.rowcnt AS DECIMAL (28, 2)) * 100.0) AS DECIMAL (28, 2)) 
              ELSE 0
              END AS '% Rows Changed'
FROM     sys.sysindexes AS s
         INNER JOIN
         sys.tables AS st
         ON st.[object_id] = s.[id]
         INNER JOIN
         sys.schemas AS ss
         ON ss.[schema_id] = st.[schema_id]
WHERE    s.id > 100
         AND s.indid > 0
ORDER BY SchemaName, TableName, IndexName

For more details, please refer: A tale (and Query) of using Catalog Views to get Index Maintenance (rebuild/reorganize) History


Nakul Vachhrajani
4 · 33% · 10564
2
 
2
 
0
Failed
 
0
Lifesaver
 
0
Production
 
0
Unwise



Submit

Your Comment


Sign Up or Login to post a comment.

"When was Index Maintenance (rebuild/reorganize) last performed on your database?" rated 5 out of 5 by 2 readers
When was Index Maintenance (rebuild/reorganize) last performed on your database? , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]