Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Nested triggers 1


Nested triggers 1

Author
Message
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5773 Visits: 7130
Thanks, Tom, i actually quite enjoyed figuring this one out.
The added complexity flavoured it up quite a bit.

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
venkat9.sql
venkat9.sql
SSC Veteran
SSC Veteran (270 reputation)SSC Veteran (270 reputation)SSC Veteran (270 reputation)SSC Veteran (270 reputation)SSC Veteran (270 reputation)SSC Veteran (270 reputation)SSC Veteran (270 reputation)SSC Veteran (270 reputation)

Group: General Forum Members
Points: 270 Visits: 260
Hugo Kornelis (4/23/2013)
The same applies to QotD authors. "Kill your darlings".(My own QotD's probably suffer from the same problem -though I don't think I've ever had *this* amount of code-. It's always easier to kill someone else's darlings).


+1
HaHa..

Tom.. I took it as a personal challenge to work out your entire question in my brain and you should see the pride when I got the answer correct only to realize after seeing the description, I didn't pay even the slightest of attention to the actual question in your question....

I did enjoy working through your Qotd though.. Thanks for it..

___________________________________________________________________
If I can answer a question then anyone can answer it..trying to reverse the logic.. Hehe
wolfkillj
wolfkillj
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1104 Visits: 2582
L' Eomot Inversé (4/23/2013)
Hugo Kornelis (4/23/2013)
The first sentence of the explanation should probably have read "Instead of triggers can cascade regardless of the setting of the nested trigger server option."

yes, you are write. Silly of me.
Hugo Kornelis (4/23/2013)
The code in this question contains:
* A somewhat complex view definition that is not immediately obvious;
* Two instead of triggers that both are, while not really complex, not immediately obvious;
* A very complicated piece of code to populate the table (really, just putting in a VALUES clause with the five rows would have been so much easier).
*this* amount of code-. It's always easier to kill someone else's darlings).

There certainly was some unneccessary complexity. But that was intentional. You may recall that a few weeks back I responded to something (I can't remember what) in the forums with the comment that it was tempting me to produce a nasty complex question using instead of triggers. I resisted the temptation for a few days, but then succumbed and this was part of the result. Actually I reduced the complexity a lot from the first version, but it's still rather complex for a QotD.
I don't think the method of populating the table is unreasonable though - but maybe it is with only 5 rows (the original had varchar(27) instead of varchar(6) and 27 rows - using @ to Z instead of 5 using A to E).


The main quibble I have with the question was that figuring out the contents the dbo.tmp1 table would have been unreasonably time-consuming had I not just created the objects and executed a SELECT * FROM dbo.tmp1.

I couldn't figure out what the triggers would do until I knew what data was in the table, and trying to work it out from the formula would have taken longer than it took me to (a) figure out that the question hinged on the (non)effect on INSTEAD OF triggers of turning off nested triggers and (b) trace the execution of the DELETEs through the firing of the triggers to determine the final result.

Taking that long to puzzle out the sample data, and running the risk of a wrong answer if I made a mistake in doing so, seemed unreasonable to me when the generation of the sample data has nothing to do with the subject of the question. A simple INSERT INTO . . . VALUES construct would have put the data right there for me to see, and from there, I could have worked out the answer without running any code.

Tom, had you included 27 rows in the sample data instead of 5, you would probably have a mob of torch- and pitchfork-wielding SSC members at your door this morning!

The question does a great job of highlighting the fact that turning off nested triggers only affects AFTER triggers - that's the kind of esoteric SQL Server knowledge that I like to learn from a QotD!

Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21075 Visits: 18259
Thanks Tom.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Revenant
Revenant
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5772 Visits: 4709
It took a while... Thanks, Tom!
Rune Bivrin
Rune Bivrin
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3720 Visits: 1461
tl;dr


Just because you're right doesn't mean everybody else is wrong.
Miles Neale
Miles Neale
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2666 Visits: 1694
Thanks Tom, got it but it took a while.

Not all gray hairs are Dinosaurs!
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16441 Visits: 13202
Long question, but interesting.



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 SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10704 Visits: 12001
Carlo Romagnano (4/23/2013)
What is the difference between the answer 3 and 6?
5, 3, 1

I don't think there is any. But the answers may tell us two interesting things: (i) when two answers are the same, more people pick the first than the second; (ii) even when people know only one item on the list can be right, a few will still pick one of a pair of duplicate entries. Of course the number of responses that pick one of those two (only about 60 so far) may be so small that it doesn't reliably tell us anything.

Actually, I suspect that one of those was a typing error on my part and should have been 5,3,2. But I'm not sure - I was trying to complicate things at the time and two equal options might have struck me as an amusing complication, although I don't remember it.

Tom

malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2009 Visits: 1189
Nice question. But little bit lengthy code.

Malleswarareddy
I.T.Analyst
MCITP(70-451)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search