估算每天数据库的更新量


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
--估算每天数据库的更新量

DECLARE @starttime DATETIME
SELECT @starttime = sqlserver_start_time 
FROM sys.dm_os_sys_info --取服务器启动时间

--按索引表中最大的更新量来估算
SELECT name,user_updates,last_user_update, 日平均
FROM (
	SELECT
	tbl.name,user_updates
	,ius.last_user_update,
	user_updates/(DATEDIFF(mi,@starttime,last_user_update)*1.0/(24*60)) 日平均
	,ROW_NUMBER() OVER( PARTITION BY name ORDER BY user_updates DESC )n
	FROM
	sys.dm_db_index_usage_stats ius 
	INNER JOIN sys.tables tbl ON tbl.OBJECT_ID = ius.OBJECT_ID
	WHERE  ius.user_updates !=0 AND ius.database_id = DB_ID()
)m
WHERE m.n = 1 
ORDER BY m.日平均 DESC