Loading...
 
JoiWiki » Developer » Databases » SQL Scripts » SQL Transaction Scripts SQL Transaction Scripts

SQL Transaction Scripts

Transaction Scripts

Transactions are great, so great in fact that you can read about them specifically here: SQL Transactions. Here are a few copy/paste scripts to use:

 

 

 

begin tran
rollback tran

--commit tran


-- Queries to check the status of transactions on the database
-- Dont leave transactions open for no reason!
select * from sys.dm_tran_session_transactions

SELECT Tst.Session_id, er.status, er.blocking_session_id, Tst.Enlist_count, er.start_time, er.wait_time, er.total_elapsed_time
, login_name,Host_name,Program_name,Text
FROM  SYS.Dm_tran_session_transactions Tst
INNER JOIN SYS.Dm_exec_connections Ec ON Tst.Session_id = Ec.Session_id
INNER JOIN SYS.Dm_exec_sessions Es ON Tst.Session_id = Es.Session_id
left join sys.dm_exec_requests er on er.session_id = Ec.session_id
CROSS APPLY SYS.DM_EXEC_SQL_TEXT(Ec.Most_recent_sql_handle)
--where program_name = 'Microsoft SQL Server Management Studio - Query'
--where program_name = 'Microsoft SQL Server Management Studio - Query'

 

 

 

 

 

 

 

 

Created by JBaker. Last Modification: Tuesday February 11, 2020 11:37:34 GMT by JBaker.

Developer