April 23, 2009 at 12:21 pm
whether XACT_ABORT ON can be used in a stored procedure where you never use begin tran commit or rollback.
i have 2 insert, 1 updates, 1 delete in a stored procedure where there are no transactions. first are inserts, second updates & third deletes. all three operations use different tables & not on same table. whether using XACT_ABORT ON inside the proc will rollback any changes made in the previous batch i.e.> if there are any issue while performing a delete will rollback any changes made by inserts & updates without using begin tran when XACT_ABORT is set to ON?
Thanks
April 23, 2009 at 2:28 pm
Test it and find out, in a dev database. That's what I'd do. If it actually matters which it will do, is there a reason to not use begin...commit?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 23, 2009 at 7:49 pm
RJ (4/23/2009)
whether XACT_ABORT ON can be used in a stored procedure where you never use begin tran commit or rollback.i have 2 insert, 1 updates, 1 delete in a stored procedure where there are no transactions. first are inserts, second updates & third deletes. all three operations use different tables & not on same table. whether using XACT_ABORT ON inside the proc will rollback any changes made in the previous batch i.e.> if there are any issue while performing a delete will rollback any changes made by inserts & updates without using begin tran when XACT_ABORT is set to ON?
Thanks
It won't do anything for you without explicit transactions on a system that's setup to do implicit transactions for each Insert/Update/Delete.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 24, 2009 at 7:38 am
Test it and find out, in a dev database. That's what I'd do. If it actually matters which it will do, is there a reason to not use begin...commit?
- GSquared
The reasons are i have a delete statement followed up a email sending loop. For whoever records are removed from the system I have to send emails to their manager's. if i put a begin tran to delete a record & send emails in loop to the manager's the whole table would be locked until the emails are all sent to each managers.
so i was wondering if i can make delete records as a batch & send emails in a loop.
after some testing on dev I found without begin tran if i use Xact_abort on the transactions are rolled back for a single transaction like insert, update or delete but not for the whole batches inside a procedure.
Also, i never wanted to send emails after delete by locking table until all emails are send. nevertheless, I think i have a solution.
Thank you guys.
April 26, 2009 at 9:42 am
after some testing on dev I found without begin tran if i use Xact_abort on the transactions are rolled back for a single transaction like insert, update or delete but not for the whole batches inside a procedure.
Then this is almost as good as having xact_abort OFF...Right?
Saurabh Dwivedy
___________________________________________________________
My Blog: http://tinyurl.com/dwivedys
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537
April 28, 2009 at 8:35 am
We used XACT ABORT ON where I worked. The biggest issue we had was if you were to call another stored proc within the stored proc using XACT ABORT ON. The XACT ABORT ON only applied to the first proc and was not active within the called proc. Might be careful in such a case.
April 29, 2009 at 8:31 am
Thanks that's a good point worth being on the lookout for.
Saurabh Dwivedy
___________________________________________________________
My Blog: http://tinyurl.com/dwivedys
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537
April 29, 2009 at 8:48 am
That caused a 4 table update to only update some tables and not others and changes did not get rolled back in tables that had already been updated in the called procs. Caused numerous issues for us.
February 3, 2010 at 1:16 am
Can you send working (smallest) example that shows problem with calling procedures and xact_abort ? My testing showed that XACT_ABORT is behaving like a property of a session, not a procedure context. So, if you call a procedure within procedure, it does't matter, it behaves like you copied code of subprocedure and placed it in calling procedure. So, I don't see the problem you described. Please, post example that shows problem you experience. And exact version of database.
February 3, 2010 at 6:07 am
rburgess (4/29/2009)
That caused a 4 table update to only update some tables and not others and changes did not get rolled back in tables that had already been updated in the called procs. Caused numerous issues for us.
I know it's an old post but since someone else hit on it today, I'll ask the question... were all of those updates contained in a single explicit transaction that starts with BEGIN TRANSACTION or are you just saying that you had a similar problem as the OP because you didn't?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply