Sunday, 4 October 2026

What Happens If We Issue COMMIT Twice

 If we issue COMMIT twice for a single transaction, SQL Server will commit the transaction on the first COMMIT. The second COMMIT will fail because there is no active transaction left to commit.

SQL Server raises:

Msg 3902

The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

Let’s see the example

BEGIN TRANSACTION; 

UPDATE Account

SET Balance = Balance - 10000

WHERE AccountNumber = 'SB100001'; 

COMMIT;

It will commit the transaction.

Now I am issuing the Commit second time in this session.

BEGIN TRANSACTION; 

UPDATE Account

SET Balance = Balance - 10000

WHERE AccountNumber = 'SB100001';

COMMIT;

 COMMIT;

Getting the below error.


 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts