码迷,mamicode.com
首页 > 数据库 > 详细

Sql Server 获取数据库最近执行的操作

时间:2018-10-16 16:00:03      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:ring   class   else   cross   ast   from   ase   sub   取数据   

 

 

select top 1000 s2.dbid,

DB_NAME(s2.dbid) as [dbname],
(select top 1 substring(s2.text,statement_start_offset/2+1,
((case when statement_end_offset=-1
then( len(convert(nvarchar(max),s2.text))*2)
else statement_end_offset end)- statement_start_offset)/2+1)
)as sqll,


 last_execution_time as [time] 


 from sys.dm_exec_query_stats as s1 cross apply sys.dm_exec_sql_text(sql_handle) as s2
 where s2.objectid is null 
 order by  last_execution_time desc
SELECT
	TOP 1000 s2.dbid,
	DB_NAME(s2.dbid) AS [dbname],
	(
		SELECT
			TOP 1 SUBSTRING (
				s2. TEXT,
				statement_start_offset / 2 + 1,
				(
					(
						CASE
						WHEN statement_end_offset =- 1 THEN
							(
								len(
									CONVERT (nvarchar(MAX), s2. TEXT)
								) * 2
							)
						ELSE
							statement_end_offset
						END
					) - statement_start_offset
				) / 2 + 1
			)
	) AS sqll,
	last_execution_time AS [time]
FROM
	sys.dm_exec_query_stats AS s1 CROSS apply sys.dm_exec_sql_text (sql_handle) AS s2
WHERE
	s2.objectid IS NULL
ORDER BY
	last_execution_time DESC

  

Sql Server 获取数据库最近执行的操作

标签:ring   class   else   cross   ast   from   ase   sub   取数据   

原文地址:https://www.cnblogs.com/lhlong/p/9797886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!