DBCC OPENTRAN (Transact-SQL)
Displays information about the oldest active transaction and the oldest distributed and nondistributed replicated transactions, if any, within the specified database. Results are displayed only if there is an active transaction or if the database contains replication information. An informational message is displayed if there are no active transactions.
DBCC OPENTRAN is not supported for non-SQL Server Publishers.
Use DBCC OPENTRAN to determine whether an open transaction exists within the transaction log. When you use the BACKUP LOG statement, only the inactive part of the log can be truncated; an open transaction can prevent the log from truncating completely. To identify an open transaction, use sp_who to obtain the system process ID.
A. Returning the oldest active transaction
The following example obtains transaction information for the current database. Results may vary.
Here is the result set.
Transaction information for database 'master'.
Oldest active transaction:
SPID (server process ID) : 52
UID (user ID) : -1
Name : user_transaction
LSN : (518:1576:1)
Start time : Jun 1 2004 3:30:07:197PM
SID : 0x010500000000000515000000a065cf7e784b9b5fe77c87709e611500
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
The "UID (user ID)" result is meaningless and will be removed in a future version of SQL Server.
B. Specifying the WITH TABLERESULTS option
The following example loads the results of the DBCC OPENTRAN command into a temporary table.
-- Create the temporary table to accept the results. CREATE TABLE #OpenTranStatus ( ActiveTransaction varchar(25), Details sql_variant ) -- Execute the command, putting the results in the table. INSERT INTO #OpenTranStatus EXEC ('DBCC OPENTRAN WITH TABLERESULTS, NO_INFOMSGS'); -- Display the results. SELECT * FROM #OpenTranStatus; GO