Search notes:

SQL Server: @@trancount

@@trancount counts the nested transactions.
print '@@trancount = ' + str(@@trancount) -- 0

begin transaction;
--
-- Starting a transaction increments the transaction counter
--
print '@@trancount = ' + str(@@trancount); -- 1

begin transaction;
print '@@trancount = ' + str(@@trancount); -- 2

save transaction sp_tq84;
--
-- A savepoint does not increase the transaction counter
--
print '@@trancount = ' + str(@@trancount); -- 2

begin transaction;
print '@@trancount = ' + str(@@trancount); -- 3

begin transaction;
print '@@trancount = ' + str(@@trancount); -- 4

commit;
print '@@trancount = ' + str(@@trancount); -- 3

rollback transaction sp_tq84;
--
-- Rolling back to a savepoint does not decrease the
-- transaction counter:
--
print '@@trancount = ' + str(@@trancount); -- 3

go
--
-- Apparently, a 'go' has no effect on active transactions:
--
print '@@trancount = ' + str(@@trancount); -- 3

rollback;
--
-- A rollback sets the transaction counter to 0:
--
print '@@trancount = ' + str(@@trancount); -- 0
Github repository about-MSSQL, path: /t-sql/variables/@@/trancount.sql

See also

@@ variables

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206419, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/T-SQL/variables/atat/trancount(84): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78