SQL Server 任务监控脚本
程序员文章站
2022-05-16 18:10:03
...
http://webnesbay.com/sql-server-jobs-monitoring-script/ SQL Server BEGIN DECLARE @jobstatusTABLE(Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int, Next_Run_Time int,Next_Run_Schedule_ID int, Requested_To_Run
http://webnesbay.com/sql-server-jobs-monitoring-script/ SQL ServerBEGIN DECLARE @jobstatus TABLE(Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int, Next_Run_Time int,Next_Run_Schedule_ID int, Requested_To_Run int, Request_Source int, Request_Source_ID varchar(100), Running int, Current_Step int, Current_Retry_Attempt int, State int) INSERT INTO @jobstatus EXEC MASTER.dbo.xp_sqlagent_enum_jobs 1,garbage BEGIN SELECT DISTINCT CASE WHEN state=1 THEN 'Job is Executing' WHEN state=2 THEN 'Waiting for thread to complete' WHEN state=3 THEN 'Between retries' WHEN state=4 THEN 'Job is Idle' WHEN state=5 THEN 'Job is suspended' WHEN state=7 THEN 'Performing completion actions' END AS State,sj.name, CASE WHEN ej.running=1 THEN st.step_id ELSE 0 END AS currentstepid, CASE WHEN ej.running=1 THEN st.step_name ELSE 'not executing' END AS currentstepname, st.command, ej.request_source_id FROM @jobstatus ej join msdb..sysjobs sj ON sj.job_id=ej.job_id JOIN msdb..sysjobsteps st ON st.job_id=ej.job_id AND (st.step_id=ej.current_step or ej.current_step=0) WHERE ej.running+1>1 END END
推荐阅读
-
SQL SERVER数据库的作业的脚本及存储过程
-
基于SQL Server OS的任务调度机制详解
-
sql server通过脚本进行数据库压缩全备份的方法【推荐】
-
EFCore 通过实体Model生成创建SQL Server数据库表脚本
-
简单的SQL Server备份脚本代码
-
sql server编写archive通用模板脚本实现自动分批删除数据
-
sql server通过临时存储过程实现使用参数添加文件组脚本复用
-
SQL Server 2008R2编写脚本时智能提示功能丢失的处理方法
-
sql server重建全库索引和更新全库统计信息通用脚本
-
Sql Server 创建数据库脚本Create DATABASE