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

Charbel picture Charbel · Feb 4, 2011 · Viewed 136.5k times · Source

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 execute a query, what would happen?

Answer

marc_s picture marc_s · Feb 4, 2011

As long as you don't COMMIT or ROLLBACK a transaction, it's still "running" and potentially holding locks.

If your client (application or user) closes the connection to the database before committing, any still running transactions will be rolled back and terminated.