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
( {'database_name' | database_id}
) [ WITH TABLERESULTS [, NO_INFOMSGS]
]
If neither database_name nor database_id is specified, the default is the current database.
Use DBCC OPENTRAN to determine whether an open transaction exists within the log. When using the BACKUP LOG statement, only the inactive portion of the log can be truncated; an open transaction can cause the log to not truncate completely. In earlier versions of Microsoft® SQL Server™, either all users had to log off or the server had to be shut down and restarted to clear uncommitted transactions from the log. With DBCC OPENTRAN, an open transaction can be identified (by obtaining the system process ID from the sp_who output) and terminated, if necessary.
DBCC OPENTRAN returns this result set when there are no open transactions:
No active open transactions.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC OPENTRAN permissions default to members of the sysadmin fixed server role or the db_owner fixed database role, and are not transferable.
This example obtains transaction information for the current database and for the pubs database.
-- Display transaction information only for the current database.
DBCC OPENTRAN
GO
-- Display transaction information for the pubs database.
DBCC OPENTRAN('pubs')
GO
This example obtains the transaction information in a table form, and then loads the information into a SQL Server table.
-- Generate the output in table form.
DBCC OPENTRAN('pubs') WITH TABLERESULTS
GO
-- Put transaction information into the table
DECLARE @string VARCHAR (255)
SELECT @string = "DBCC OPENTRAN('pubs') WITH TABLERESULTS"
SELECT @string
-- Create the table.
CREATE TABLE #opentran_output
(trantag varchar(30), tranvalue varchar(46))
-- Use INSERT INTO...EXEC to load into the table.
INSERT INTO #opentran_output
EXEC (@string)
GO
--Display the results.
SELECT *
FROM #opentran_output
GO
BEGIN TRANSACTION | ROLLBACK TRANSACTION |
COMMIT TRANSACTION | DBCC |
DB_ID |