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»»»

Triggers 2 Expand / Collapse
Author
Message
Posted Wednesday, April 24, 2013 8:39 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:35 AM
Points: 6,133, Visits: 8,397
Comments posted to this topic are about the item Triggers 2


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1446274
Posted Wednesday, April 24, 2013 11:28 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, December 14, 2014 11:09 PM
Points: 1,962, Visits: 2,406
Good question Hugo
This time I am able to grab the points ....
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/
Post #1446300
Posted Wednesday, April 24, 2013 11:29 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
Great question hugo. Last week i asked a question related to this kind of scenario.




Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1446301
Posted Thursday, April 25, 2013 12:21 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 10:18 AM
Points: 1,057, Visits: 2,359
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.
Post #1446308
Posted Thursday, April 25, 2013 2:01 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 @ 1:10 PM
Points: 3,115, Visits: 3,239
Nice QotD!

Thanks
IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1446335
Posted Thursday, April 25, 2013 2:05 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 10:51 AM
Points: 4,158, Visits: 5,556
Nice question, thanks Hugo

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #1446337
Posted Thursday, April 25, 2013 3:48 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:21 PM
Points: 7,928, Visits: 9,653
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
Post #1446376
Posted Thursday, April 25, 2013 3:54 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, December 14, 2014 11:09 PM
Points: 1,962, Visits: 2,406
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/
Post #1446380
Posted Thursday, April 25, 2013 4:02 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:35 AM
Points: 6,133, Visits: 8,397
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!



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1446385
Posted Thursday, April 25, 2013 6:56 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: Tuesday, September 30, 2014 7:42 AM
Points: 3,688, Visits: 72,435
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*




--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Post #1446469
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse