Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss content posted by bitbucket
»
Transactions 2
57 posts, Page 1 of 6
1
2
3
4
5
»
»»
Transactions 2
Rate Topic
Display Mode
Topic Options
Author
Message
bitbucket-25253
bitbucket-25253
Posted Tuesday, May 22, 2012 8:35 PM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 9:21 AM
Points: 5,099,
Visits: 20,191
Comments posted to this topic are about the item
Transactions 2
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please
read
Before posting a performance problem please
read
Post #1304651
sanjeewan99
sanjeewan99
Posted Tuesday, May 22, 2012 10:12 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, March 12, 2013 7:23 AM
Points: 114,
Visits: 386
Good question !!!
Post #1304670
Henrico Bekker
Henrico Bekker
Posted Tuesday, May 22, 2012 10:53 PM
SSCommitted
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:24 AM
Points: 1,871,
Visits: 2,692
this question look very familiar......
too bad i got it wrong...again.
----------------------------------------------
Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.
Post #1304677
Koen Verbeeck
Koen Verbeeck
Posted Tuesday, May 22, 2012 11:24 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 6:54 AM
Points: 9,364,
Visits: 6,462
Very nice question, definately learned something.
Got it wrong, as I say "begin transaction" I immediately thought "rollback everything". Apparently not
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1304679
Nakul Vachhrajani
Nakul Vachhrajani
Posted Tuesday, May 22, 2012 11:55 PM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,277,
Visits: 1,608
Good question with a couple of learning points.
1. By default SQL does not abort the entire transaction if it encounters a statment-level failure. In this case, the primary key violation is a statement level failure and hence, only the statement terminated, not the entire transaction
If the requirement is to cause a failure of the entire transaction (i.e. abort), then the following SET option needs to be set to ON:
SET XACT_ABORT ON
Setting XACT_ABORT to ON will cause SQL Server to abort the transaction even if it encounteres the statement level failure.
2. Referring one of my blog posts, row constructors (introduced in SQL Server 2008) process the entire batch at once. Hence, had this example used row constructors, the correct answer would have been 0 rows affected (Reference post:
http://beyondrelational.com/modules/2/blogs/77/Posts/14434/0159-sql-server-row-constructors-triggers-process-the-entire-batch-at-once.aspx
)
Thank-you!
Thanks & Regards,
Nakul Vachhrajani.
http://beyondrelational.com/modules/2/blogs/77/nakuls-blog.aspx
Be courteous. Drive responsibly.
Follow me on
Twitter:
@nakulv_sql
Google Plus:
+Nakul
Post #1304697
john.straver
john.straver
Posted Wednesday, May 23, 2012 12:35 AM
Valued Member
Group: General Forum Members
Last Login: Friday, April 19, 2013 8:07 AM
Points: 61,
Visits: 29
the answer is 0 rows when xact_abort is set to on
the answer is 2 rows when xact_abort is set to off
Post #1304713
Nakul Vachhrajani
Nakul Vachhrajani
Posted Wednesday, May 23, 2012 12:43 AM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,277,
Visits: 1,608
john.straver (5/23/2012)
the answer is 0 rows when xact_abort is set to on
the answer is 2 rows when xact_abort is set to off
By default, SET XACT_ABORT is OFF.
Thanks & Regards,
Nakul Vachhrajani.
http://beyondrelational.com/modules/2/blogs/77/nakuls-blog.aspx
Be courteous. Drive responsibly.
Follow me on
Twitter:
@nakulv_sql
Google Plus:
+Nakul
Post #1304721
Neil Thomas
Neil Thomas
Posted Wednesday, May 23, 2012 12:44 AM
Old Hand
Group: General Forum Members
Last Login: Wednesday, January 09, 2013 6:26 AM
Points: 347,
Visits: 170
So that means that when xact_abort is set to off then
BEGIN TRANSACTION
...
COMMIT TRANSACTION
does not do as expected.
What's the default setting on a fresh install of SQL?
Post #1304722
Neil Thomas
Neil Thomas
Posted Wednesday, May 23, 2012 12:45 AM
Old Hand
Group: General Forum Members
Last Login: Wednesday, January 09, 2013 6:26 AM
Points: 347,
Visits: 170
Neil Thomas (5/23/2012)
So that means that when xact_abort is set to off then
BEGIN TRANSACTION
...
COMMIT TRANSACTION
does not do as expected.
What's the default setting on a fresh install of SQL?
Ah, an additional comment has been added whilst I wrote this.
That's a bit of a gotcha isn't it?
Post #1304723
IgorMi
IgorMi
Posted Wednesday, May 23, 2012 1:09 AM
SSCommitted
Group: General Forum Members
Last Login: Today @ 10:15 AM
Points: 1,869,
Visits: 1,426
Nakul Vachhrajani (5/22/2012)
Good question with a couple of learning points.
1. By default SQL does not abort the entire transaction if it encounters a statment-level failure. In this case, the primary key violation is a statement level failure and hence, only the statement terminated, not the entire transaction
If the requirement is to cause a failure of the entire transaction (i.e. abort), then the following SET option needs to be set to ON:
SET XACT_ABORT ON
Setting XACT_ABORT to ON will cause SQL Server to abort the transaction even if it encounteres the statement level failure.
2. Referring one of my blog posts, row constructors (introduced in SQL Server 2008) process the entire batch at once. Hence, had this example used row constructors, the correct answer would have been 0 rows affected (Reference post:
http://beyondrelational.com/modules/2/blogs/77/Posts/14434/0159-sql-server-row-constructors-triggers-process-the-entire-batch-at-once.aspx
)
Thank-you!
The question is interesting. I first thought the select would give 0 rows, but then i remind myself that XACT_ABORT is set to OFF by default.
Thank you
IgorMi
Post #1304732
« Prev Topic
|
Next Topic »
57 posts, Page 1 of 6
1
2
3
4
5
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.