Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Nested triggers 1 Expand / Collapse
Author
Message
Posted Tuesday, April 23, 2013 7:40 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 7:50 AM
Points: 3,859, Visits: 5,001
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”
Post #1445425
Posted Tuesday, April 23, 2013 8:09 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Saturday, July 26, 2014 10:14 AM
Points: 212, Visits: 224
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..
Post #1445451
Posted Tuesday, April 23, 2013 9:01 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 3:21 PM
Points: 1,210, Visits: 2,512
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
Post #1445496
Posted Tuesday, April 23, 2013 9:54 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 11:08 PM
Points: 21,230, Visits: 14,940
Thanks Tom.



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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1445544
Posted Tuesday, April 23, 2013 11:11 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 7:53 AM
Points: 4,386, Visits: 3,396
It took a while... Thanks, Tom!
Post #1445588
Posted Wednesday, April 24, 2013 4:40 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:21 AM
Points: 2,988, Visits: 901
tl;dr


Just because you're right doesn't mean everybody else is wrong.
Post #1445848
Posted Thursday, April 25, 2013 9:34 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 1:18 PM
Points: 2,266, Visits: 1,320
Thanks Tom, got it but it took a while.

Not all gray hairs are Dinosaurs!
Post #1446573
Posted Friday, April 26, 2013 12:39 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:12 AM
Points: 13,283, Visits: 10,157
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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1446810
Posted Friday, April 26, 2013 1:38 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 7:29 PM
Points: 8,562, Visits: 9,063
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
Post #1446829
Posted Monday, April 29, 2013 2:15 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, July 21, 2014 3:43 AM
Points: 1,938, Visits: 1,162
Nice question. But little bit lengthy code.

Malleswarareddy
I.T.Analyst
MCITP(70-451)
Post #1447399
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse