sql - Does SET XACT_ABORT ON do anything in a stored procedure if you're NOT in a transaction? -
does set xact_abort on in stored procedure if you're not in transaction?
i'm asking stored procedure appears somehow rolling insert statement thought part of stored procedure failing not in transaction. identity of table being pushed inserted rows not there after stored procedure returns, despite fact insert unconditional , not inside transaction.
or there other reason why sql server roll insert outside of transaction?
set xact_abort on
changes behavior of statement-terminating errors instead become batch-aborting errors. batch within procedure executing more stop when error encountered, rather continuing on next t-sql statement.
this has implications error-handling. statement-terminating errors allow continue , execute handling code via if @@error <> 0
block within procedure not executed. what's worse, there no way can intercept batch-abortion in t-sql code, unless there check on @@error
in following batch on same connection, might not know there problem.
perhaps insert
failing quietly in way still allows identity
seed incremented. not uncommon...identity values reside in sql server memory cache, volatility of provides no guarantee values continuous , without gaps.
alternatively, calling context of stored procedure matters. if called within outer-scope transaction, either initiated sql server or @ application level, rollback @ outer scope rollback inner scope work, regardless of explicit transaction handling code @ inner scope. again, identity
seed incremented.
try/catch
blocks (available since sql server 2005) obviate need set xact_abort on
.
Comments
Post a Comment