程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> SQL Server 任務監控腳本

SQL Server 任務監控腳本

編輯:關於SqlServer

SQL Server 任務監控腳本

http://webnesbay.com/sql-server-jobs-monitoring-script/

代碼:

BEGIN

 
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
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved