SQL Server 查出未提交事务(长事务)SQL

DECLARE @tab TABLE(NAME varchar(100),value varchar(200))

INSERT INTO @tab
EXEC('DBCC OPENTRAN WITH TABLERESULTS')
SELECT name,CAST(value AS DATETIME) startDate,getdate() currentDate,
DATEDIFF(SECOND,CAST(value AS DATETIME),getdate()) diffsecond FROM @tab WHERE name in 
('OLDACT_STARTTIME')

SELECT spid,
blocked,
DB_NAME(sp.dbid) AS DBName,
program_name,
waitresource,
lastwaittype,
sp.loginame,
sp.hostname,
a.[Text] AS [TextData],
SUBSTRING(A.text, sp.stmt_start / 2, 
(CASE WHEN sp.stmt_end = -1 THEN DATALENGTH(A.text) ELSE sp.stmt_end 
END - sp.stmt_start) / 2) AS [current_cmd]
FROM sys.sysprocesses AS sp OUTER APPLY sys.dm_exec_sql_text (sp.sql_handle) AS A
WHERE spid =(SELECT value FROM @tab WHERE name in 
('OLDACT_SPID') )

 

你可能感兴趣的:(SQL Server 查出未提交事务(长事务)SQL)