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?

指定したホスト名が生成したSQL Serverのプロセスを取得し、spidを求める

Posted at

--概要   :指定したホスト名が生成したSQL Serverのプロセスを取得し、spidを返します。
--引数   :[@hostname]...ホスト名
--戻り値  :正常終了なら0、そうでなければ-1
--結果セット:正常終了した場合、指定したホストのspid結果リスト
--      例外が発生した場合、エラー情報
CREATE PROCEDURE [sp_get_process]
@hostname VARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;

--spidを取得します。
BEGIN TRY
    SELECT [spid]
    FROM [sys].[sysprocesses] WITH (nolock)
    WHERE [hostname] = @hostname
    AND [spid] <> @@spid
    ORDER BY [spid];
END TRY
BEGIN CATCH
    EXECUTE sp_returnerror 'sp_get_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?