SQL Server 任务监控脚本

来源:未知 责任编辑:智问网络 发表时间:2013-10-30 11:12 点击:
BEGIN
02
 
03
 
04
DECLARE @jobstatus
05
 
06
TABLE(Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int,
07
 
08
    Next_Run_Time int,Next_Run_Schedule_ID int, Requested_To_Run int,
09
 
10
    Request_Source int, Request_Source_ID varchar(100),
11
 
12
Running int, Current_Step int, Current_Retry_Attempt int, State int)
13
 
14
INSERT INTO @jobstatus
15
 
16
EXEC MASTER.dbo.xp_sqlagent_enum_jobs 1,garbage
17
 
18
                BEGIN
19
 
20
                SELECT DISTINCT CASE
21
                   WHEN state=1 THEN 'Job is Executing'
22
                   WHEN state=2 THEN 'Waiting for thread to complete'
23
                   WHEN state=3 THEN 'Between retries'
24
                   WHEN state=4 THEN 'Job is Idle'
25
                   WHEN state=5 THEN 'Job is suspended'
26
                   WHEN state=7 THEN 'Performing completion actions'
27
 
28
                END AS State,sj.name,
29
 
30
                CASE WHEN ej.running=1 THEN st.step_id ELSE 0 END AS currentstepid,
31
                CASE WHEN ej.running=1 THEN st.step_name ELSE 'not executing' END AS currentstepname,
32
 
33
                st.command, ej.request_source_id
34
 
35
                FROM @jobstatus ej join msdb..sysjobs sj ON sj.job_id=ej.job_id
36
 
37
                JOIN msdb..sysjobsteps st ON st.job_id=ej.job_id AND (st.step_id=ej.current_step or ej.current_step=0)
38
 
39
                WHERE ej.running+1>1
40
 
41
                END
42
 
43
END


摘自 sunyh的博客
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • sql常见面试题
    • SQL SERVER 2005性能之跟踪
    • SQL编程(一)
    • LINUX上RMAN自动备份脚本
    • sql server面试题
    • 如何将多个SQL查询统计结果一次显示出来
    • 浅谈SQL Server中的事务日志(三)----在简单恢复模式下日志的角色
    • SQL小技巧系列 --- 行转列合并
    • sql server 列转行
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1