0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

指定したspidのプロセスを削除

Posted at

--概要   :指定したspidのプロセスを削除します。
--引数   :[@target_spid]...プロセスを削除するspid
--戻り値  :正常終了なら0、そうでなければ-1
--結果セット:例外が発生した場合、エラー情報
CREATE PROCEDURE [sp_kill_process]
@target_spid SMALLINT
AS
BEGIN
SET NOCOUNT ON;

--KILLコマンドを実行する動的SQLを作成します。
--※「KILL @spid;」はエラーとなるため、動的SQLで対応
DECLARE @sql VARCHAR(MAX);
SET @sql = 'KILL ' + CONVERT(VARCHAR, @target_spid);

--spidを削除します。
BEGIN TRY
    EXECUTE (@sql);
END TRY
BEGIN CATCH
    EXECUTE sp_returnerror 'sp_kill_process:プロセスの削除に失敗しました。';
    RETURN (-1);
END CATCH

--正常終了を返します。
RETURN (0);

END
GO

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?