Search

Thursday, April 11, 2013

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

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

No comments:

Post a Comment