一、作业管理
(1) select * from msdb.dbo.sysjobhistory 可以查看作业的历史记录
(2) select * from msdb.dbo.sysjobs 查看作业
(3)执行代码判断作业是否成功执行
declare @fullbakjob int;
set @fullbakjob=(SELECT case when count(HIST.run_status)=sum(HIST.run_status) then 1 else 0 end stat
FROM msdb.dbo.sysjobs JOB
INNER JOIN msdb.dbo.sysjobhistory HIST ON HIST.job_id = JOB.job_id
WHERE JOB.name in ('Db_Tank_Back_Restore')
AND HIST.run_date= convert(char(10),GetDate(),112) AND HIST.run_time<'60000');
print @fullbakjob
其中 AND HIST.run_date= convert(char(10),GetDate(),112) 是为判断是否为当天日期
其中 AND HIST.run_time<'60000' 是为运行时间在6点以前的
二、进程管理
select start_time,command,percent_complete,text,session_id,blocking_session_id
from sys.dm_exec_requests r
cross apply sys.dm_exec_sql_text(r.sql_handle) s
order by 1