sp_help_job (Transact-sql)sp_help_job (Transact-SQL)
適用対象:Applies to: SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
自動化された操作を SQL ServerSQL Server で実行するときに SQL ServerSQL Server エージェントで使用されるジョブに関する情報を返します。Returns information about jobs that are used by SQL ServerSQL Server Agent to perform automated activities in SQL ServerSQL Server.
Transact-SQL 構文表記規則
Transact-SQL Syntax Conventions
構文Syntax
sp_help_job { [ @job_id = ] job_id
[ @job_name = ] 'job_name' }
[ , [ @job_aspect = ] 'job_aspect' ]
[ , [ @job_type = ] 'job_type' ]
[ , [ @owner_login_name = ] 'login_name' ]
[ , [ @subsystem = ] 'subsystem' ]
[ , [ @category_name = ] 'category' ]
[ , [ @enabled = ] enabled ]
[ , [ @execution_status = ] status ]
[ , [ @date_comparator = ] 'date_comparison' ]
[ , [ @date_created = ] date_created ]
[ , [ @date_last_modified = ] date_modified ]
[ , [ @description = ] 'description_pattern' ]
引数Arguments
[ @job_id = ] job_id
ジョブの識別番号を指定します。[ @job_id = ] job_id
The job identification number. job_id は uniqueidentifier,、既定値は NULL です。job_id is uniqueidentifier, with a default of NULL.
[ @job_name = ] 'job_name'
ジョブの名前。[ @job_name = ] 'job_name'
The name of the job. job_name は sysname,、既定値は NULL です。job_name is sysname, with a default of NULL.
注意
特定のジョブを表示するには、 job_id または job_name のいずれかを指定する必要があります。To view a specific job, either job_id or job_name must be specified. すべてのジョブに関する情報を返すには、 job_id と job_name の両方を省略します。Omit both job_id and job_name to return information about all jobs.
[ @job_aspect = ] 'job_aspect'
表示するジョブ属性。[ @job_aspect = ] 'job_aspect'
The job attribute to display. job_aspect は varchar (9),、既定値は NULL の場合、これらの値のいずれかを指定できます。job_aspect is varchar(9), with a default of NULL, and can be one of these values.
[値]Value | 説明Description |
---|---|
ALLALL | ジョブのすべての属性情報Job aspect information |
補足JOB | ジョブ情報Job information |
出荷SCHEDULES | スケジュール情報Schedule information |
ようSTEPS | ジョブ ステップ情報Job step information |
ターゲットTARGETS | ターゲット情報Target information |
[ @job_type = ] 'job_type'
レポートに含めるジョブの種類。[ @job_type = ] 'job_type'
The type of jobs to include in the report. job_type は varchar (12),、既定値は NULL です。job_type is varchar(12), with a default of NULL. Job_type ローカル または マルチサーバーを指定できます。job_type can be LOCAL or MULTI-SERVER.
[ @owner_login_name = ] 'login_name'
ジョブの所有者のログイン名です。[ @owner_login_name = ] 'login_name'
The login name of the owner of the job. login_name は sysname,、既定値は NULL です。login_name is sysname, with a default of NULL.
[ @subsystem = ] 'subsystem'
サブシステムの名前。[ @subsystem = ] 'subsystem'
The name of the subsystem. サブシステム は nvarchar (40),、既定値は NULL です。subsystem is nvarchar(40), with a default of NULL.
[ @category_name = ] 'category'
カテゴリの名前。[ @category_name = ] 'category'
The name of the category. category は sysname,、既定値は NULL です。category is sysname, with a default of NULL.
[ @enabled = ] enabled
有効なジョブまたは無効になっているジョブの情報を表示するかどうかを示す数値です。[ @enabled = ] enabled
A number indicating whether information is shown for enabled jobs or disabled jobs. 有効 になっているは tinyint,、既定値は NULL です。enabled is tinyint, with a default of NULL. 1 は有効なジョブを示し、 0 は無効になっているジョブを示します。1 indicates enabled jobs, and 0 indicates disabled jobs.
[ @execution_status = ] status
ジョブの実行状態です。[ @execution_status = ] status
The execution status for the jobs. 状態 は int,、既定値は NULL の場合、これらの値のいずれかを指定できます。status is int, with a default of NULL, and can be one of these values.
[値]Value | 説明Description |
---|---|
00 | アイドルまたは中断されていないジョブのみを返します。Returns only those jobs that are not idle or suspended. |
11 | 実行.Executing. |
22 | スレッド待機中。Waiting for thread. |
33 | 再試行の間隔。Between retries. |
44 | [アイドル]。Idle. |
55 | 状態.Suspended. |
77 | 完了操作の実行中。Performing completion actions. |
[ @date_comparator = ] 'date_comparison'
Date_createdとdate_modifiedの比較に使用する比較演算子。[ @date_comparator = ] 'date_comparison'
The comparison operator to use in comparisons of date_created and date_modified. date_comparison は char (1),、は =, <, or > です。date_comparison is char(1),and can be =, <, or >.
[ @date_created = ] date_created
ジョブが作成された日付。[ @date_created = ] date_created
The date the job was created. date_createdは datetime,、既定値は NULL です。date_createdis datetime, with a default of NULL.
[ @date_last_modified = ] date_modified
ジョブが最後に変更された日付。[ @date_last_modified = ] date_modified
The date the job was last modified. date_modified は datetime,、既定値は NULL です。date_modified is datetime, with a default of NULL.
[ @description = ] 'description_pattern'
ジョブの説明。[ @description = ] 'description_pattern'
The description of the job. description_pattern は nvarchar (512),、既定値は NULL です。description_pattern is nvarchar(512), with a default of NULL. description_pattern には、パターンマッチングに SQL Server ワイルドカード文字を含めることができます。description_pattern can include the SQL Server wildcard characters for pattern matching.
リターン コードの値Return Code Values
0 (成功) または 1 (失敗)0 (success) or 1 (failure)
結果セットResult Sets
引数を指定しない場合、 sp_help_job はこの結果セットを返します。If no arguments are specified, sp_help_job returns this result set.
列名Column name | データ型Data type | 説明Description |
---|---|---|
job_idjob_id | uniqueidentifieruniqueidentifier | ジョブの一意の ID。Unique ID of the job. |
originating_serveroriginating_server | nvarchar(30)nvarchar(30) | ジョブの送信元のサーバーの名前。Name of the server from which the job came. |
namename | sysnamesysname | ジョブの名前。Name of the job. |
有効enabled | tinyinttinyint | ジョブの実行が有効かどうかを示します。Indicates whether the job is enabled to be executed. |
descriptiondescription | nvarchar(512)nvarchar(512) | ジョブの説明。Description for the job. |
start_step_idstart_step_id | intint | 実行を開始するジョブのステップの ID。ID of the step in the job where execution should begin. |
categorycategory | sysnamesysname | ジョブ カテゴリ。Job category. |
責任owner | sysnamesysname | ジョブ所有者。Job owner. |
notify_level_eventlognotify_level_eventlog | intint | どのような場合に、通知イベントを Microsoft Windows アプリケーションログに記録するかを示すビットマスク。Bitmask indicating under what circumstances a notification event should be logged to the Microsoft Windows application log. 次のいずれかの値を指定します。Can be one of these values: 0 = なし0 = Never 1 = ジョブが成功した場合1 = When a job succeeds 2 = ジョブが失敗したとき2 = When the job fails 3 = ジョブが完了するたびに (ジョブの結果に関係なく)3 = Whenever the job completes (regardless of the job outcome) |
notify_level_emailnotify_level_email | intint | どのような場合に、ジョブの完了時に通知電子メールを送信するかを示すビットマスク。Bitmask indicating under what circumstances a notification e-mail should be sent when a job completes. 指定できる値は、 notify_level_eventlogの場合と同じです。Possible values are the same as for notify_level_eventlog. |
notify_level_netsendnotify_level_netsend | intint | どのような場合に、ジョブの完了時にネットワークメッセージを送信するかを示すビットマスク。Bitmask indicating under what circumstances a network message should be sent when a job completes. 指定できる値は、 notify_level_eventlogの場合と同じです。Possible values are the same as for notify_level_eventlog. |
notify_level_pagenotify_level_page | intint | どのような場合に、ジョブの完了時にページを送信するかを示すビットマスク。Bitmask indicating under what circumstances a page should be sent when a job completes. 指定できる値は、 notify_level_eventlogの場合と同じです。Possible values are the same as for notify_level_eventlog. |
notify_email_operatornotify_email_operator | sysnamesysname | 通知するオペレーターの電子メール名。E-mail name of the operator to notify. |
notify_netsend_operatornotify_netsend_operator | sysnamesysname | ネットワークメッセージを送信するときに使用するコンピューターまたはユーザーの名前。Name of the computer or user used when sending network messages. |
notify_page_operatornotify_page_operator | sysnamesysname | ページを送信するときに使用するコンピューターまたはユーザーの名前。Name of the computer or user used when sending a page. |
delete_leveldelete_level | intint | どのような場合に、ジョブの完了時にジョブを削除するかを示すビットマスク。Bitmask indicating under what circumstances the job should be deleted when a job completes. 指定できる値は、 notify_level_eventlogの場合と同じです。Possible values are the same as for notify_level_eventlog. |
date_createddate_created | datetimedatetime | ジョブが作成された日付。Date the job was created. |
date_modifieddate_modified | datetimedatetime | ジョブが最後に変更された日付。Date the job was last modified. |
version_numberversion_number | intint | ジョブのバージョン (ジョブを変更するたびに自動的に更新されます)。Version of the job (automatically updated each time the job is modified). |
last_run_datelast_run_date | intint | ジョブの実行を最後に開始した日付。Date the job last started execution. |
last_run_timelast_run_time | intint | ジョブの実行を最後に開始した時刻。Time the job last started execution. |
last_run_outcomelast_run_outcome | intint | 最後に実行したときのジョブの結果:Outcome of the job the last time it ran: 0 = 失敗0 = Failed 1 = 成功1 = Succeeded 3 = キャンセル3 = Canceled 5 = 不明5 = Unknown |
next_run_datenext_run_date | intint | ジョブが次に実行されるようにスケジュールされている日付。Date the job is scheduled to run next. |
next_run_timenext_run_time | intint | ジョブの次回実行予定時刻。Time the job is scheduled to run next. |
next_run_schedule_idnext_run_schedule_id | intint | 次回の実行スケジュールの識別番号。Identification number of the next run schedule. |
current_execution_statuscurrent_execution_status | intint | 現在の実行状態:Current execution status: 1 = 実行中1 = Executing 2 = スレッドを待機しています2 = Waiting For Thread 3 = 再試行の間隔3 = Between Retries 4 = アイドル4 = Idle 5 = 中断5 = Suspended 6 = 互換性のために残されています6 = Obsolete 7 = PerformingCompletionActions7 = PerformingCompletionActions |
current_execution_stepcurrent_execution_step | sysnamesysname | ジョブの現在の実行ステップ。Current execution step in the job. |
current_retry_attemptcurrent_retry_attempt | intint | ジョブが実行中で、ステップが再試行されている場合は、これが現在の再試行です。If the job is running and the step has been retried, this is the current retry attempt. |
has_stephas_step | intint | ジョブに含まれるジョブステップの数。Number of job steps the job has. |
has_schedulehas_schedule | intint | ジョブのジョブ スケジュール数。Number of job schedules the job has. |
has_targethas_target | intint | ジョブのターゲット サーバー数。Number of target servers the job has. |
typetype | intint | ジョブの種類。Type of the job. 1 = ローカルジョブ。1 = Local job. 2 = マルチサーバージョブ。2 = Multiserver job. 0 = ジョブに対象サーバーがありません。0 = Job has no target servers. |
Job_idまたはjob_nameが指定されている場合、 sp_help_jobは、ジョブステップ、ジョブスケジュール、およびジョブ対象サーバーに対してこれらの追加の結果セットを返します。If job_id or job_name is specified, sp_help_job returns these additional result sets for job steps, job schedules, and job target servers.
次に、ジョブ ステップに関する結果セットを示します。This is the result set for job steps.
列名Column name | データ型Data type | 説明Description |
---|---|---|
step_idstep_id | intint | ステップの (このジョブで) 一意の ID。Unique (for this job) identifier for the step. |
step_namestep_name | sysnamesysname | ステップの名前。Name of the step. |
サブsubsystem | nvarchar(40)nvarchar(40) | ステップ コマンドを実行するサブシステム。Subsystem in which to execute the step command. |
commandcommand | nvarchar (3200)nvarchar(3200) | 実行するコマンド。Command to execute. |
flagsflags | nvarchar (4000)nvarchar(4000) | ステップの動作を制御する値のビットマスク。Bitmask of values that control step behavior. |
cmdexec_success_codecmdexec_success_code | intint | CmdExecステップの場合、これは成功したコマンドのプロセス終了コードです。For a CmdExec step, this is the process exit code of a successful command. |
on_success_actionon_success_action | nvarchar (4000)nvarchar(4000) | ステップが成功した場合の対処方法:What to do if the step succeeds: 1 = 正常に終了します。1 = Quit with success. 2 = エラーで終了します。2 = Quit with failure. 3 = 次の手順に進みます。3 = Go to next step. 4 = ステップに進みます。4 = Go to step. |
on_success_step_idon_success_step_id | intint | On_success_actionが4の場合は、次に実行する手順を示します。If on_success_action is 4, this indicates the next step to execute. |
on_fail_actionon_fail_action | nvarchar (4000)nvarchar(4000) | ステップが失敗した場合に実行する動作。Action to take if the step fails. 値は on_success_actionの場合と同じです。Values are the same as for on_success_action. |
on_fail_step_idon_fail_step_id | intint | On_fail_actionが4の場合は、次に実行する手順を示します。If on_fail_action is 4, this indicates the next step to execute. |
serverserver | sysnamesysname | 予約済み。Reserved. |
database_namedatabase_name | sysnamesysname | ステップの場合 Transact-SQLTransact-SQL 、これはコマンドを実行するデータベースです。For a Transact-SQLTransact-SQL step, this is the database in which the command will executes. |
database_user_namedatabase_user_name | sysnamesysname | Transact-SQLTransact-SQL ステップの場合は、コマンドを実行するデータベース ユーザー コンテキスト。For a Transact-SQLTransact-SQL step, this is the database user context in which the command executes. |
retry_attemptsretry_attempts | intint | ステップを正常に実行できない場合、コマンドを再試行する最大回数。この回数に達すると、ステップが失敗したと判断されます。Maximum number of times the command should be retried (if it is unsuccessful) before the step is deemed to have failed. |
retry_intervalretry_interval | intint | 再試行の間隔 (分単位)。Interval (in minutes) between any retry attempts. |
os_run_priorityos_run_priority | varchar (4000)varchar(4000) | 予約済み。Reserved. |
output_file_nameoutput_file_name | varchar (200)varchar(200) | コマンド出力を書き込むファイル ( Transact-SQLTransact-SQL および CmdExec ステップのみ)。File to which command output should be written (Transact-SQLTransact-SQL and CmdExec steps only). |
last_run_outcomelast_run_outcome | intint | 最後に実行したときのステップの結果。Outcome of the step the last time it ran: 0 = 失敗0 = Failed 1 = 成功1 = Succeeded 3 = キャンセル3 = Canceled 5 = 不明5 = Unknown |
last_run_durationlast_run_duration | intint | 最後に実行したときのステップの経過時間 (秒単位)。Duration (in seconds) of the step the last time it ran. |
last_run_retrieslast_run_retries | intint | 最後にステップを実行したときにコマンドが再試行された回数。Number of times the command was retried the last time the step ran. |
last_run_datelast_run_date | intint | ステップの実行を最後に開始した日付。Date the step last started execution. |
last_run_timelast_run_time | intint | ステップの実行を最後に開始した時刻。Time the step last started execution. |
proxy_idproxy_id | intint | ジョブステップのプロキシ。Proxy for the job step. |
これは、ジョブスケジュールの結果セットです。This is the result set for job schedules.
列名Column name | データ型Data type | 説明Description |
---|---|---|
schedule_idschedule_id | intint | すべてのジョブで一意なスケジュール識別子。Identifier of the schedule (unique across all jobs). |
schedule_nameschedule_name | sysnamesysname | スケジュールの名前 (このジョブでのみ一意)。Name of the schedule (unique for this job only). |
有効enabled | intint | スケジュールがアクティブである (1) かどうか (0)。Whether the schedule is active (1) or not (0). |
freq_typefreq_type | intint | ジョブをいつ実行するかを示す値。Value indicating when the job is to be executed: 1 = 1 回1 = Once 4 = 日単位4 = Daily 8 = 週単位8 = Weekly 16 = 月単位16 = Monthly 32 = 毎月、 freq_intervalに対して相対的32 = Monthly, relative to the freq_interval 64 = SQLServerAgent サービスの開始時に実行します。64 = Run when SQLServerAgent service starts. |
freq_intervalfreq_interval | intint | ジョブが実行された日。Days when the job is executed. 値は freq_typeの値によって異なります。The value depends on the value of freq_type. 詳細については、「 sp_add_schedule (transact-sql) 」を参照してください。For more information, see sp_add_schedule (Transact-SQL) |
freq_subday_typefreq_subday_type | IntInt | Freq_subday_intervalの単位。Units for freq_subday_interval. 詳細については、「 sp_add_schedule (transact-sql) 」を参照してください。For more information, see sp_add_schedule (Transact-SQL) |
freq_subday_intervalfreq_subday_interval | intint | ジョブの各実行間に発生する freq_subday_type 期間の数。Number of freq_subday_type periods to occur between each execution of the job. 詳細については、「 sp_add_schedule (transact-sql) 」を参照してください。For more information, see sp_add_schedule (Transact-SQL) |
freq_relative_intervalfreq_relative_interval | intint | スケジュールされたジョブの各月の freq_interval の発生。Scheduled job's occurrence of the freq_interval in each month. 詳細については、「 sp_add_schedule (transact-sql) 」を参照してください。For more information, see sp_add_schedule (Transact-SQL) |
freq_recurrence_factorfreq_recurrence_factor | intint | スケジュールされたジョブの実行間隔 (月数)。Number of months between the scheduled execution of the job. |
active_start_dateactive_start_date | intint | ジョブの実行を開始する日付。Date to begin execution of the job. |
active_end_dateactive_end_date | intint | ジョブの実行を終了する日付。Date to end execution of the job. |
active_start_timeactive_start_time | intint | Active_start_date でジョブの実行を開始する時刻 。Time to begin the execution of the job on active_start_date. |
active_end_timeactive_end_time | intint | Active_end_dateでジョブの実行を終了する時刻。Time to end execution of the job on active_end_date. |
date_createddate_created | datetimedatetime | スケジュールが作成された日付。Date the schedule is created. |
schedule_descriptionschedule_description | nvarchar (4000)nvarchar(4000) | スケジュールの英語の説明 (要求された場合)。An English description of the schedule (if requested). |
next_run_datenext_run_date | intint | スケジュールによってジョブが次に実行される日付。Date the schedule will next cause the job to run. |
next_run_timenext_run_time | intint | スケジュールによってジョブが次に実行される時刻。Time the schedule will next cause the job to run. |
schedule_uidschedule_uid | uniqueidentifieruniqueidentifier | スケジュールの識別子。Identifier for the schedule. |
job_countjob_count | intint | このスケジュールを参照するジョブの数。Returns the number of jobs that reference this schedule. |
次に、ジョブターゲット サーバーに関する結果セットを示します。This is the result set for job target servers.
列名Column name | データ型Data type | 説明Description |
---|---|---|
server_idserver_id | intint | 対象サーバーの識別子。Identifier of the target server. |
server_nameserver_name | nvarchar(30)nvarchar(30) | 対象サーバーのコンピューター名。Computer name of the target server. |
enlist_dateenlist_date | datetimedatetime | 対象サーバーをマスターサーバーに参加させた日付。Date the target server enlisted into the master server. |
last_poll_datelast_poll_date | datetimedatetime | 対象サーバーが最後にマスターサーバーをポーリングした日付。Date the target server last polled the master server. |
last_run_datelast_run_date | intint | ターゲット サーバーでジョブの実行を最後に開始した日付。Date the job last started execution on this target server. |
last_run_timelast_run_time | intint | ターゲット サーバーでジョブの実行を最後に開始した時刻。Time the job last started execution on this target server. |
last_run_durationlast_run_duration | intint | 対象サーバーで最後に実行されたときのジョブの期間。Duration of the job the last time it ran on this target server. |
last_run_outcomelast_run_outcome | tinyinttinyint | このサーバーで最後に実行されたときのジョブの結果:Outcome of the job the last time it ran on this server: 0 = 失敗0 = Failed 1 = 成功1 = Succeeded 3 = キャンセル3 = Canceled 5 = 不明5 = Unknown |
last_outcome_messagelast_outcome_message | nvarchar(1024)nvarchar(1024) | この対象サーバーで最後に実行されたときのジョブからの結果メッセージ。Outcome message from the job the last time it ran on this target server. |
アクセス許可Permissions
既定では、 sysadmin 固定サーバーロールのメンバーは、このストアドプロシージャを実行できます。By default, members of the sysadmin fixed server role can execute this stored procedure. 他のユーザーには、 SQL ServerSQL Server msdb データベースの次のいずれかの エージェント固定データベース ロールが許可されている必要があります。Other users must be granted one of the following SQL ServerSQL Server Agent fixed database roles in the msdb database:
SQLAgentUserRoleSQLAgentUserRole
SQLAgentReaderRoleSQLAgentReaderRole
SQLAgentOperatorRoleSQLAgentOperatorRole
これらのロールの権限の詳細については、「 SQL Server エージェントの固定データベース ロール」を参照してください。For details about the permissions of these roles, see SQL Server Agent Fixed Database Roles.
SQLAgentUserRoleのメンバーは、自分が所有しているジョブのみを表示できます。Members of SQLAgentUserRole can only view jobs that they own. Sysadmin、 SQLAgentReaderRole、およびSqlagentoperatorroleのメンバーは、すべてのローカルジョブとマルチサーバージョブを表示できます。Members of sysadmin, SQLAgentReaderRole, and SQLAgentOperatorRole can view all local and multiserver jobs.
例Examples
A.A. すべてのジョブの情報を一覧表示するList information for all jobs
次の例では、パラメーターを指定せずにプロシージャを実行し、 sp_help_job
データベースで現在定義されているすべてのジョブの情報を返し msdb
ます。The following example executes the sp_help_job
procedure with no parameters to return the information for all of the jobs currently defined in the msdb
database.
USE msdb ;
GO
EXEC dbo.sp_help_job ;
GO
B.B. 特定の条件に一致するジョブの情報を一覧表示するListing information for jobs matching a specific criteria
次の例では、françoisa
が所有するマルチサーバー ジョブのジョブ情報を一覧表示します。ここでは、有効でかつ、実行中のジョブが対象になります。The following example lists job information for the multiserver jobs owned by françoisa
where the job is enabled and executing.
USE msdb ;
GO
EXEC dbo.sp_help_job
@job_type = N'MULTI-SERVER',
@owner_login_name = N'françoisa',
@enabled = 1,
@execution_status = 1 ;
GO
C.C. ジョブに関するすべての属性情報を一覧表示するListing all aspects of information for a job
次の例では、NightlyBackups
ジョブに関するすべての属性情報を一覧表示します。The following example lists all aspects of the information for the job NightlyBackups
.
USE msdb ;
GO
EXEC dbo.sp_help_job
@job_name = N'NightlyBackups',
@job_aspect = N'ALL' ;
GO
参照See Also
sp_add_job (Transact-SQL) sp_add_job (Transact-SQL)
sp_delete_job (Transact-sql) sp_delete_job (Transact-SQL)
sp_update_job (Transact-sql) sp_update_job (Transact-SQL)
システム ストアド プロシージャ (Transact-SQL)System Stored Procedures (Transact-SQL)