SQL SERVER – BEGIN END VS BEGIN TRAN/COMMIT/ROLLBACK

Today I got an interesting question from Preethy kammath my colleague.

The question is what is the difference between BEGIN….END VS BEGIN TRAN/COMMIT/ROLLBACK?

The answer is

  • BEGIN…END

Begin……End delimits a block of code. IF there is no BEGIN TRAN inside the BEGIN…END then each statement will execute in an autonomous transaction.

  • BEGIN TRAN…COMMIT TRAN … Rollback

In this each statement inside this block is executed in the same transaction and cannot be committed or rolled back individually.

Hope every one understood the concept. More discussions are welcome.

print

2 thoughts on “SQL SERVER – BEGIN END VS BEGIN TRAN/COMMIT/ROLLBACK

  1. … [Trackback]…

    […] Informations on that Topic: sqlinfo.in/2010/12/sql-server-trancommitrollback/ […]…

  2. Author’s gravatar

    Very useful information about BEGIN END vs BEGIN TRANS, i looked somewhere but no one give clear info.. thanks varun

Leave a Reply

Your email address will not be published. Required fields are marked *


six + 3 =