Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I currently have an application that allows data entry. It's been in use for over a year and now I'd like to add two columns to the table in the database (SQL Server 2000) that the data is stored in. The first column will be a date called "FirstCreated" and I want it to always store the date the row was originally created. The second column is also a date called "LastUpdated" this should always be the date that the row was last updated/changed on. I know how to do this is my code but I was wondering is there a way to add these columns and have SQL Server do the date updating automatically? This way I don't have to hunt down every place I change or create rows in my code and add this functionality in. I was thinking in the "Formula" section in the design table wizard maybe there was a way to do this.

 

Thanks,

OnTheAnvil

Posted
use a trigger for the 'lastupdated' column on UPDATE statements. Make FirstCreated have a default value of NOW(). I don't know how to create triggers on ms sql server =/
Posted

Thanks HJB417. Now for a performance question: Do triggers take any significant amount of processing power on a system that has a large number of updates or are they relatively trivial? Also, does anyone else know how to set up triggers? I can probably figure it out by trial and error but I'd rather not screw it up.

 

Thanks.

  • Administrators
Posted

http://www.xtremedotnettalk.com/showthread.php?t=92281 gives a very basic idea of the syntax needed to create a trigger, if you want a more specific example just ask...

The performance impact of a trigger really depends on what the trigger does, simply updating a field shouldn't cause too much in terms of performance issues - however other aspects (indexing, validation) may add their own overheads.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...