Code/Tea/Etc...

Duncan Mackenzie has too much time on his hands

New Poll is up and a silly mistake...

One of the big reasons I redesigned the poll component, was so that I could track votes over time... I did this by adding a 'dateVoted' column to my vote table, and then using an “On Insert” trigger to set that column to the current date/time.... peachy keen, except when I exported the tables and stored procs to my live SQL box, I forgot to include my triggers... so all the votes on my previous poll have no date/time info. Yeesh. Oh well, not a big deal since I'm still in the testing/building stage, but still a very silly mistake.

I've put up a new poll though... I have a lot of article ideas for my Coding 4 Fun columns and I thought I'd ask people what topic they would like to see sooner rather than later...

 

Published Saturday, July 10, 2004 2:50 PM by Duncanma

Comments

 

David Hayden said:

Hey Duncan,

I am curious as to why you are using a trigger as opposed to just setting the 'dateVoted' column in code? On a lot of my tables I often have a 'CreateDate' field with the date the row was added to the table and a 'ModifyDate' when the row was last updated. I normally just populate these fields via code as opposed to a trigger, but I always wondered what I would gain if I used a trigger. Assuming the application I created is the only way rows are added and modified, does a trigger help me in any way?

BTW, why do you mention "Tea" in the name of your blog? :) Are you a fan of tea, the drink?
July 10, 2004 4:38 PM
 

Duncan Mackenzie said:

David... I prefer to use triggers for the date created and date modified because, even if your code is supposed to be the only way to edit the data, people often end up using new tools and/or things like SQL Enterprise Manager...

oh, and yeah... big fan of the tea :)
July 10, 2004 8:14 PM
 

Sonu Kapoor said:

Mistakes happens. After all we are just humans :-)
BTW: I love tea too especially indian tea.
July 11, 2004 4:23 AM
 

David Hayden said:

Thanks for the answer, Duncan!

I will use triggers on my personal project to get a feel for the difference in functionality and maintenance. My customers are not technically savvy enough to modify the data outside of the web application, but I agree that ideally these "rules" should be in the database itself.

I am a big fan of tea as well. I drink green tea daily and am enjoying it so much I told my wife we have to start an online store by year's end :)
July 11, 2004 6:49 AM
 

Michael Falconer said:

Hi Duncan,

How about just setting the default value for the dateVoted column to getDate()? As good as a trigger (albeit the value can be overwritten when accessnig the table directly), but will be included when you export/script the table...

P.S. I'm an ex-tea drinker!!
July 12, 2004 5:39 AM
 

DeanG said:

Where is the Question for the latest poll displayed at?
July 13, 2004 1:01 PM
 

Duncan Mackenzie said:

July 13, 2004 1:02 PM
 

Kent Sharkey said:

An example of D's tea fetish.

I just went into his "supplier's" shop in Winnipeg, and after ordering 2# of his brew of choice, I was asked, "Is this for ... Mackenzie?"

...Where everyone knows your name...
July 13, 2004 6:34 PM
 

Feroz said:

Hi Duncan:

I agree with Michael Falconer. Is there any specific reason to choose trigger over default value?
July 14, 2004 10:56 AM
Anonymous comments are disabled

This Blog

Syndication

News

This blog has moved to my own VB site

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker