April 24, 2013 at 8:39 pm
Comments posted to this topic are about the item Triggers 2
April 24, 2013 at 11:28 pm
Good question Hugo 🙂
This time I am able to grab the points :-P....
Last time I forgot to see the Go batch separator and comments and clicked on wrong one!!!
Thanks!!
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 24, 2013 at 11:29 pm
Great question hugo. Last week i asked a question related to this kind of scenario. 🙂
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
April 25, 2013 at 12:21 am
Awesome, thank you for posting.
(first thing I noticed this time was the missing of "EXISTS" in trigger and then "= 1" condition, that made it easy to mark the correct choice after running the code couple of time in the head)
ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
April 25, 2013 at 2:01 am
Nice QotD!
Thanks
IgorMi
Igor Micev,My blog: www.igormicev.com
April 25, 2013 at 2:05 am
This was removed by the editor as SPAM
April 25, 2013 at 3:48 am
Good question and explanation.
Triggers that work only on single rows are a common problem, so anything that points out the pitfalls and warns people not to write them is a good thing.
But I have a minor quibble: if this is a business rule, it should be enforced by the schema if possible, not by code; and this is a classic example of a rule that can be enforced by a check constraint.
Tom
April 25, 2013 at 3:54 am
L' Eomot Inversé (4/25/2013)
Good question and explanation.Triggers that work only on single rows are a common problem, so anything that points out the pitfalls and warns people not to write them is a good thing.
But I have a minor quibble: if this is a business rule, it should be enforced by the schema if possible, not by code; and this is a classic example of a rule that can be enforced by a check constraint.
+1 🙂
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 25, 2013 at 4:02 am
L' Eomot Inversé (4/25/2013)
But I have a minor quibble: if this is a business rule, it should be enforced by the schema if possible, not by code; and this is a classic example of a rule that can be enforced by a check constraint.
For a production implementation, I fully agree that a trigger, even a well-coded one, would be a terrible way to implement this rule.
But for a QotD about triggers, using a CHECK constraint would not have been a very smart choice! 😉
April 25, 2013 at 6:56 am
I needs my coffee... for some reason I was reading the question as... how many rows will be returned... and I saw the count(*) and went... 1 duh.... there's no group by...
apparently reading is something I completely forgot... *sigh* *watches pot brewing*
April 25, 2013 at 7:00 am
I was surprised this was your question Hugo. I didn't think it was yours when I saw the Count(*) in the trigger! 😉
April 25, 2013 at 8:21 am
Great question, another correction to allow it to work is changing "= 1" to "> 0", obviously without the quotes included.
Thanks,
Lon
April 25, 2013 at 8:45 am
Good question. The code was easier to follow than most lately. Thanks.
April 25, 2013 at 9:30 am
Nice +1.
Not all gray hairs are Dinosaurs!
April 25, 2013 at 9:49 am
Thanks Hugo.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 15 posts - 1 through 15 (of 26 total)
You must be logged in to reply to this topic. Login to reply