Reputation: 2093
Is there a way to execute a single SQL Server T-SQL statement from within a transaction block that is excluded from the transaction?
For example, we want to write to a status table periodically during a batch process, that is within a transaction to advise how far through the process has been completed (see reason below), but if the batch process fails and the transaction is rolled back, the record written into the status table should remain intact.
Reason for writing into the status table as we go along is so that the progress through the batch can be monitored as the batch runs.
Upvotes: 0
Views: 58
Reputation: 1270391
What you are looking for has a name (at least in Oracle): autonomous transaction. If you Google "autonomous transaction sql server", you will get references such as this and this.
There are basically three approaches in SQL Server:
Neither of these is fully satisfying, but they are viable work-arounds.
Upvotes: 2