jobs.sp_stop_job (Azure エラスティック ジョブ) (Transact-SQL)

適用対象:Azure SQL Database

Azure SQL Database の Azure Elastic Jobs サービスでジョブの実行を 停止するようにエラスティック ジョブ エージェントに指示します

このストアド プロシージャは、SQL Server エージェント サービスの sp_stop_job SQL Server の同様のオブジェクトと名前を共有します。 SQL Server エージェントバージョンの詳細については、「sp_stop_job (Transact-SQL)」を参照してください

Transact-SQL 構文表記規則

構文

[jobs].sp_stop_job [ @job_execution_id = ] ' job_execution_id '

引数

@job_execution_id

停止するジョブ実行の ID 番号。 job_execution_idは uniqueidentifier で、既定値は NULL.

リターン コードの値

0 (成功) または 1 (失敗)

アクセス許可

既定では、このストアド プロシージャを実行できるのは、 sysadmin 固定サーバー ロールのメンバーです。 このストアド プロシージャを使って、他のユーザーが所有するジョブの属性を編集できるのは、sysadmin のメンバーだけです。

解説

エラスティック ジョブのすべての時間は、UTC タイム ゾーンが適用されます。

現在のジョブ実行をjob_execution_id識別するには、jobs.job_executionsを使用します。

ジョブの実行を識別して停止する

次の例は、jobs.job_executionsジョブの実行を識別し、次に01234567-89ab-cdef-0123-456789abcdef例を使用してジョブの実行をjob_execution_id取り消す方法を示しています。

job_database に接続して、次のコマンドを実行します。

--Connect to the job database specified when creating the job agent

-- View all active executions to determine job_execution_id
SELECT job_name
, job_execution_id
, job_version
, step_id
, is_active
, lifecycle
, start_time
, current_attempts
, current_attempt_start_time
, last_message
, target_group_name
, target_server_name
, target_database_name
FROM jobs.job_executions
WHERE is_active = 1 AND job_name = 'ResultPoolsJob'
ORDER BY start_time DESC;
GO

-- Cancel job execution with the specified job_execution_id
EXEC jobs.sp_stop_job '01234567-89ab-cdef-0123-456789abcdef';