Search code examples
sql-servert-sqltransactionsrollback

Are all statements in a stored procedure ONE transaction


If a stored procedure contains multiple statements e.g. first an insert, then an update and finally a deletes and the stored procedure gets killed in the middle of the delete, does the insert and update also have to be rolled back? Or does it only roll back the delete i.e. the implicit transaction?


Solution

  • As explained in Transactions, each statement will be executed as an implicit transaction. If a statement fails then the effect of prior statements will remain committed.

    Note that the entire stored procedure may be executed within an explicit transaction created by the calling code.