ql 서버 조회 잠금 저장 프로세스

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[sp_who_lock]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[sp_who_lock]
GO
 
USE master
GO
CREATE PROCEDURE sp_who_lock
AS
BEGIN
DECLARE @spid INT,@bl INT,
        @intTransactionCountOnEntry INT,
        @intRowcount INT,
        @intCountProperties INT,
        @intCounter INT
 
        CREATE TABLE #tmp_lock_who (
         id INT IDENTITY(1,1),
         spid SMALLINT,
         bl SMALLINT)
 
        IF @@ERROR<>0 RETURN @@ERROR
 
        INSERT INTO #tmp_lock_who(spid,bl) SELECT 0 ,blocked
          FROM (SELECT * FROM sysprocesses WHERE blocked>0 ) a
          WHERE NOT EXISTS(SELECT * FROM (SELECT * FROM sysprocesses WHERE blocked>0 ) b
          WHERE a.blocked=spid)
          UNION SELECT spid,blocked FROM sysprocesses WHERE blocked>0
 
        IF @@ERROR<>0 RETURN @@ERROR
 
--          
        SELECT @intCountProperties = COUNT(*),@intCounter = 1
        FROM #tmp_lock_who
 
        IF @@ERROR<>0 RETURN @@ERROR
 
        IF @intCountProperties=0
            SELECT '           ' AS message
 
--    
while @intCounter <= @intCountProperties
BEGIN
--       
        SELECT @spid = spid,@bl = bl
        FROM #tmp_lock_who WHERE Id = @intCounter
        BEGIN
            IF @spid =0
                SELECT '         : '+ CAST(@bl AS VARCHAR(10)) + '   ,    SQL    '
            ELSE
                SELECT '   SPID:'+ CAST(@spid AS VARCHAR(10))+ ' ' + '   SPID:'+ CAST(@bl AS VARCHAR(10)) +'  ,        SQL    '
            DBCC INPUTBUFFER (@bl )
            END
 
--      
        SET @intCounter = @intCounter + 1
END
 
DROP TABLE #tmp_lock_who
 
RETURN 0
END

좋은 웹페이지 즐겨찾기