查看 SQL Server 作业(job)运行结果状态脚本
查看 SQL Server 作业(job) 运行成功与否、还是取消等状态信息,以及作业最后一次运行持续时间、出错信息提示等。DBA 可以周期性地调度该 SQL 脚本,在 SQL Server 作业失败时候得到及时提醒
select category = jc.name,
category_id = jc.category_id,
job_name = j.name,
job_enabled = j.enabled,
last_run_time = cast(js.last_run_date as varchar(10)) + '-' + cast(js.last_run_time as varchar(10)),
last_run_duration = js.last_run_duration,
last_run_status = js.last_run_outcome,
last_run_msg = js.last_outcome_message + cast(nullif(js.last_run_outcome,1) as varchar(2)),
job_created = j.date_created,
job_modified = j.date_modified
from msdb.dbo.sysjobs j
inner join msdb.dbo.sysjobservers js
on j.job_id = js.job_id
inner join msdb.dbo.syscategories jc
on j.category_id = jc.category_id
where j.enabled = 1
and js.last_run_outcome in (0,1,3,5) -- 0:Fail 1:Succ 3:Cancel 5:First run
and jc.category_id not between 10 and 20 -- repl
/*
category_id name
0 [Uncategorized (Local)]
1 Jobs from MSX
2 [Uncategorized (Multi-Server)]
3 Database Maintenance
4 Web Assistant
5 Full-Text
6 Log Shipping
7 Database Engine Tuning Advisor
10 REPL-Distribution
11 REPL-Distribution Cleanup
12 REPL-History Cleanup
13 REPL-LogReader
14 REPL-Merge
15 REPL-Snapshot
16 REPL-Checkup
17 REPL-Subscription Cleanup
18 REPL-Alert Response
19 REPL-QueueReader
20 Replication
98 [Uncategorized]
99 [Uncategorized]
*/
更多相关文章
- 如果在详细信息表中找到记录,则显示Y / N列
- Android 通过读取本地Arp表获取当前局域网内其他设备信息
- Android App性能信息获取方法
- 教您使用java爬虫gecco抓取JD全部商品信息
- 【JAVA】通过ISBN一键获取书籍信息
- Java第三次作业——面向对象基础(封装)
- android MediaScanner 扫出来的ID3 MP3文件演唱者信息 乱码
- 导航架构组件 - 具有CollapsingToolbar的详细信息视图
- java-信息安全(三)-PBE加密算法