SqlServer查询某⼀段时间内执⾏的Sql语句
在某⼀段时间中执⾏过的SQL语句,代码如下:
SELECT TOP ation_time, , (QS.statement_start_offset / 2) + 1,
((CASE QS.statement_end_offset WHEN - 1 THEN ) ELSE QS.statement_end_offset END - QS.statement_start_offset) / 2) + 1)
AS statement_text, ST.text, QS.total_worker_time, QS.last_worker_time, QS.max_worker_time, QS.min_worker_time
FROM sys.dm_exec_query_stats QS CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) ST
ation_time BETWEEN '2020-12-15 1:00:00' AND '2020-12-15 12:00:00' LIKE '%%'
ORDER ation_time DESC;
SELECT TOP 100
QS.CREATION_TIME 时间,
SUBSTRING(ST.TEXT,(QS.STATEMENT_START_OFFSET/2)+1,((CASE QS.STATEMENT_END_OFFSET WHEN -1 THEN DATALENGTH(ST.TEXT) ELSE QS.S ST.TEXT AS 语句,
QS.TOTAL_WORKER_TIME AS 总执⾏时间毫秒,
QS.LAST_WORKER_TIME AS 上次执⾏时间毫秒,
QS.MAX_WORKER_TIME AS 最⼤执⾏时间毫秒,select语句查询日期
QS.MIN_WORKER_TIME AS 最⼩执⾏时间毫秒
FROM SYS.DM_EXEC_QUERY_STATS QS
CROSS APPLY SYS.DM_EXEC_SQL_TEXT(QS.SQL_HANDLE) ST
WHERE QS.CREATION_TIME BETWEEN CONVERT(VARCHAR(10),GETDATE(),23) AND CONVERT(VARCHAR(10),GETDATE()+1,23)
ORDER BY QS.TOTAL_WORKER_TIME DESC
检测是否表中存在某些数据,存在则执⾏下⼀个语句:
if EXISTS (select * from s_params where ParamName = 'test1' and ParamValue = 0)
begin
select * from s_params where ParamName = 'test2'
end
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论