因服务器需要迁移,需要将现有JOB迁移至新服务器,待服务器调整完毕,则重新迁移到原服务器,所以在做迁移之前希望将现有JOB进行备份,不至于乱了执行时间。
1.查看所有作业列表
USE master
SELECT
[sJOB].[job_id] AS [JobID]
, [sJOB].[name] AS [JobName]
, [sDBP].[name] AS [JobOwner]
, [sCAT].[name] AS [JobCategory]
, [sJOB].[description] AS [JobDescription]
, CASE [sJOB].[enabled]
WHEN 1 THEN 'Yes'
WHEN 0 THEN 'No'
END AS [IsEnabled]
, [sJOB].[date_created] AS [JobCreatedOn]
, [sJOB].[date_modified] AS [JobLastModifiedOn]
, [sSVR].[name] AS [OriginatingServerName]
, [sJSTP].[step_id] AS [JobStartStepNo]
, [sJSTP].[step_name] AS [JobStartStepName]
, CASE
WHEN [sSCH].[schedule_uid] IS NULL THEN 'No'
ELSE 'Yes'
END AS [IsScheduled]
, [sSCH].[schedule_uid] AS [JobScheduleID]
, [sSCH].[name] AS [JobScheduleName]
, CASE [sJOB].[delete_level]
WHEN 0 THEN 'Never'
WHEN 1 THEN 'On Success'
WHEN 2 THEN 'On Failure'
WHEN 3 THEN 'On Completion'
END AS [JobDeletionCriterion]
FROM
[msdb].[dbo].[sysjobs] AS [sJOB]
LEFT JOIN [msdb].[sys].[servers] AS [sSVR]
ON [sJOB].[originating_server_id] = [sSVR].[server_id]
LEFT JOIN [msdb].[dbo].[syscategories] AS [sCAT]
ON [sJOB].[category_id] = [sCAT].[category_id]
LEFT JOIN [msdb].[dbo].[sysjobsteps] AS [sJSTP]
ON [sJOB].[job_id] = [sJSTP].[job_id]
AND [sJOB].[start_step_id] = [sJSTP].[step_id]
LEFT JOIN [msdb].[sys].[database_principals] AS [sDBP]
ON [sJOB].[owner_sid] = [sDBP].[sid]
LEFT JOIN [msdb].[dbo].[sysjobschedules] AS [sJOBSCH]
ON [sJOB].[job_id] = [sJOBSCH].[job_id]
LEFT JOIN [msdb].[dbo].[sysschedules] AS [sSCH]
ON [sJOBSCH].[schedule_id] = [sSCH].[schedule_id]
ORDER BY [JobName]
2.查看最近一次作业执行情况
USE master
SELECT
[sJOB].[job_id] AS [JobID]
, [sJOB].[name] AS [JobName]
, CASE
WHEN [sJOBH].[run_date] IS NULL OR [sJOBH].[run_time] IS NULL THEN NULL
ELSE CAST(
CAST([sJOBH].[run_date] AS CHAR(8))
+ ' '
+ STUFF(
STUFF(RIGHT('000000' + CAST([sJOBH].[run_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
AS DATETIME)
END AS [LastRunDateTime]
, CASE [sJOBH].[run_status]
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'Running' -- In Progress
END AS [LastRunStatus]
, STUFF(
STUFF(RIGHT('000000' + CAST([sJOBH].[run_duration] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
AS [LastRunDuration (HH:MM:SS)]
, [sJOBH].[message] AS [LastRunStatusMessage]
, CASE [sJOBSCH].[NextRunDate]
WHEN 0 THEN NULL
ELSE CAST(
CAST([sJOBSCH].[NextRunDate] AS CHAR(8))
+ ' '
+ STUFF(
STUFF(RIGHT('000000' + CAST([sJOBSCH].[NextRunTime] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
AS DATETIME)
END AS [NextRunDateTime]
FROM
[msdb].[dbo].[sysjobs] AS [sJOB]
LEFT JOIN (
SELECT
[job_id]
, MIN([next_run_date]) AS [NextRunDate]
, MIN([next_run_time]) AS [NextRunTime]
FROM [msdb].[dbo].[sysjobschedules]
GROUP BY [job_id]
) AS [sJOBSCH]
ON [sJOB].[job_id] = [sJOBSCH].[job_id]
LEFT JOIN (
SELECT
[job_id]
, [run_date]
, [run_time]
, [run_status]
, [run_duration]
, [message]
, ROW_NUMBER() OVER (
PARTITION BY [job_id]
ORDER BY [run_date] DESC, [run_time] DESC
) AS RowNumber
FROM [msdb].[dbo].[sysjobhistory]
WHERE [step_id] = 0
) AS [sJOBH]
ON [sJOB].[job_id] = [sJOBH].[job_id]
AND [sJOBH].[RowNumber] = 1
ORDER BY [JobName]
3.查看作业步骤
在msdb库中执行
sp_help_jobstep 'AF168757-4F01-44A6-AC59-4DDAED6F8FED' (作业ID)
4.查看所有作业
在msdb库中执行
sp_help_job --无参数
5.查看作业时间间隔等
在msdb库中执行
sp_help_jobschedule 'AF168757-4F01-44A6-AC59-4DDAED6F8FED'(作业ID)
来自CSDN:http://bbs.csdn.net/topics/390393172
- SQL语句调优 - 统计信息的含义与作用及维护计算
统计信息的含义与作用 ...
- 【查询优化】怎样用SQL语句查看查询的性能指标
一.SET STATISTICS IO (有关TSQL语句查询所产生的磁盘活动量) --显示有关由Transact-SQL 语句生成的磁盘活动量的信息 SET STATISTICS IO ON -- ...
- 怎样用SQL语句查看查询的性能指标
一.SET STATISTICS IO (有关TSQL语句查询所产生的磁盘活动量) 扫描计数:在查询中涉及到的表被访问的次数: 逻辑读取:从数据缓冲中读取的数据页数: 物理读取:从物理磁盘中往缓冲读 ...
- sqlserver sql语句查看分区记录数、查看记录所在分区
select count(1) ,$PARTITION.WorkDatePFN(workdate) from imgfile group by $PARTITION.WorkDatePFN(workd ...
- PL/SQL 如何查看当前连接信息以及SQL PLUS如何指定IP地址
1.通过PL/SQL 想连接别的数据库可以通过在服务名前面加上IP和左斜线来实现: 2.有时我们的IP和左斜线不用输也能连别的数据库,是因为在一个文件里配置好了.这个文件在哪里? 在这个路径下的 NE ...
- Sql语句查看表结构
快速查看表对的就说明,及表字段描述及字段类型 --表描述 SELECT tbs.name 表名,ds.value 描述 FROM sys.extended_properties ds LEFT JOI ...
- 怎么用sql语句查看某个字段值是否是唯一的
select count(*) from table group by zd having count(*)>1 这是不唯一的过滤出来的语句
- sql语句查看库里有没有这张表,有就删除
查看库里有没有这张表,有就删除 DROP TABLE IF EXISTS 表名
- oracle数据库视图,序列,索引的sql语句查看
1.视图:相当于表,可以用select * from tab;查看所有表和视图: 2.序列和索引可以利用select * from user_indexes 或者user_sequences;进行查看 ...
随机推荐
- CSS 实现背景半透明
IE过渡滤镜 + CSS3 rgba 即可完美实现. 具体实现代码如下: .transparent { background:rgba(0, 0, 0, 0.3); filter:pr ...
- jsp空页面导致的jvm heap溢出
为了性能测试需要,写一个了简单的jsp页面: <%@ page contentType="text/html;charset=UTF-8" language="ja ...
- [状压dp]HDOJ4539 郑厂长系列故事——排兵布阵
中文题,题意不再赘述 对于“?”这一格,它所能攻击到的(曼哈顿距离为2的) 前方的 即“√”的四个位置 那么与此格有关的即它前方两行(即状压这两行) 首先预处理每行能满足的: i 和(i<< ...
- asp 下拉框二级联动
<script language = "JavaScript"> //js开始 var aaa;//定义aaa变量 aaa=0;//aaa赋0 bb = new Arr ...
- 如何让centos6.5在vm11里上网,连接网络?
如何让centos在vm里连接网络?步骤有3,方可解决: 1.配置vm的虚拟网络编辑器 2.配置虚拟机centos 3.设置centos的ip地址 一.配置vm的虚拟网络编辑器
- leetcode面试准备:Kth Largest Element in an Array
leetcode面试准备:Kth Largest Element in an Array 1 题目 Find the kth largest element in an unsorted array. ...
- wzplayer for android V1.5.3 (新增YUV文件播放)
wzplayer for android V1.5.3 新增功能 1.使用gl es2 播放 yuv 文件. 联系方式:weinyzhou86@gmail.com QQ:514540005 版权所有, ...
- 放在jsp头部的代码
String path = request.getContextPath(); String basePath = request.getScheme()+"://"+reques ...
- 手机端的mousedown
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Google Chrome中的高性能网络(二)
Chrome Predictor的预测功能优化 Chrome会随着使用变得更快. 它这个特性是通过一个单例对象Predictor来实现的.这个对象在浏览器内核进程(Browser Kernel Pro ...