I'm trying to write to a log file inside a transaction so that the log survives even if the transaction is rolled back.
–start code
begin tran
insert [something] into dbo.logtable
[[main code here]]
rollback
commit
— end code
You could say just do the log before the transaction starts but that is not as easy because the transaction starts before this S-Proc is run (i.e. the code is part of a bigger transaction)
So, in short, is there a way to write a special statement inside a transaction that is not part of the transaction. I hope my question makes sense.
Best Answer
Use a table variable (@temp) to hold the log info. Table variables survive a transaction rollback.
See this article.