@@ trancount (Transact-sql)
Geçerli bağlantının oluşmuş BEGIN TRANSACTION deyimlerini sayısını döndürür.
Transact-SQL Sözdizim Kuralları
Sözdizimi
@@TRANCOUNT
Dönüş Türleri
integer
Açıklamalar
BEGIN TRANSACTION deyimi @@ trancount 1 arttırır. rollback TRANSACTION azaltır @@ trancount 0 rollback TRANSACTION haricinde savepoint_name, hangi @@ trancount etkilemez. TRANSACTION COMMIT veya COMMIT work 1 @@ trancount azaltma.
Örnekler
A.BEGIN ve tamamlama deyimleri efektleri gösterme
Aşağıdaki örnek, iç içe etkisini BEGINve COMMITifadeler var @@TRANCOUNTdeğişkeni.
PRINT @@TRANCOUNT
-- The BEGIN TRAN statement will increment the
-- transaction count by 1.
BEGIN TRAN
PRINT @@TRANCOUNT
BEGIN TRAN
PRINT @@TRANCOUNT
-- The COMMIT statement will decrement the transaction count by 1.
COMMIT
PRINT @@TRANCOUNT
COMMIT
PRINT @@TRANCOUNT
--Results
--0
--1
--2
--1
--0
PRINT @@TRANCOUNT
-- The BEGIN TRAN statement will increment the
-- transaction count by 1.
BEGIN TRAN
PRINT @@TRANCOUNT
BEGIN TRAN
PRINT @@TRANCOUNT
-- The COMMIT statement will decrement the transaction count by 1.
COMMIT
PRINT @@TRANCOUNT
COMMIT
PRINT @@TRANCOUNT
--Results
--0
--1
--2
--1
--0
B.BEGIN ve rollback deyimleri efektleri gösterme
Aşağıdaki örnek, iç içe etkisini BEGIN TRANve ROLLBACKifadeler var @@TRANCOUNTdeğişkeni.
PRINT @@TRANCOUNT
-- The BEGIN TRAN statement will increment the
-- transaction count by 1.
BEGIN TRAN
PRINT @@TRANCOUNT
BEGIN TRAN
PRINT @@TRANCOUNT
-- The ROLLBACK statement will clear the @@TRANCOUNT variable
-- to 0 because all active transactions will be rolled back.
ROLLBACK
PRINT @@TRANCOUNT
--Results
--0
--1
--2
--0
PRINT @@TRANCOUNT
-- The BEGIN TRAN statement will increment the
-- transaction count by 1.
BEGIN TRAN
PRINT @@TRANCOUNT
BEGIN TRAN
PRINT @@TRANCOUNT
-- The ROLLBACK statement will clear the @@TRANCOUNT variable
-- to 0 because all active transactions will be rolled back.
ROLLBACK
PRINT @@TRANCOUNT
--Results
--0
--1
--2
--0
Ayrıca bkz.
Başvuru
BEGIN TRANSACTION (Transact-SQL)
TAMAMLAMA hareket (Transact-sql)