Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getdate as default value 1

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
US
Hi,

If the def value for a col is (getdate()),
will the col get updated every time anything in that row is changed.... or is it updated only on the initial insert of that row?

thanks, john
 
oh nevermind. Sorry to waste your time.

I experimented and found that No it doesn't
update a datetime col with the new time every time the column gets changed. You have to do that in your code (for ex in VB LastChanged = (now())

 
If you want a date field to update every time it is modified (touched), you probably will want to use an update trigger to update the field whenever any data is modified in the table.

Hope this helps,
John
 
john76,

how would you do that? I mean how would you do a trigger that would update like a 'updated_date' field, everytime a particular row is updated? thanks!
 
John,

Did you ever get an answer on how to use a trigger to update a CreateDate or LastUpdate date?

Mike Krausnick
Dublin, California
 
within a trigger

update table1
set lastupdateDAte = getdate()
FROM table1, inserted
WHERE table1.idfield = inserted.idfield

This should update the last modified date everytime the rigger runs.


Questions about posting. See faq183-874
 
Cool! Thanks so much! Is 'inserted' is a pseudo table containing the record that was inserted? Would I also use 'inserted' to reference the ID on a modified record or would that be a 'updated' or some such?

Mike Krausnick
Dublin, California
 
yep, there are two pseudotables, inserted and deleted. THe first holds the new values (in an update) or the new record (In an insert). Deleted holds the old values or the record to be deleted. These pseudotables are only accessible ina trigger.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top