What happens if you don't commit a transaction to a database (say, SQL Server)?

前端 未结 9 2287
礼貌的吻别
礼貌的吻别 2020-11-27 03:08

Suppose I have a query:

begin tran
-- some other sql code

And then I forget to commit or roll back.

If another client tries to exec

9条回答
  •  不知归路
    2020-11-27 03:10

    Transactions are intended to run completely or not at all. The only way to complete a transaction is to commit, any other way will result in a rollback.

    Therefore, if you begin and then not commit, it will be rolled back on connection close (as the transaction was broken off without marking as complete).

提交回复
热议问题