Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to fill default datetime on insert Update

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2005-11-21 : 11:07:52
I have a field in my table called Last_updated which is a datetime field, in the table design i put for that field under default value as Getdate()

When i add a new row to table it is filling the datatime automatically to field last_updated but when i make any changes to the field it does'nt do nothing.

Can you please tell me how can i put the current datetime to the cell last_updated field.

Thank you very much for info.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-11-21 : 11:11:21
use a:
1. after update trigger
2. if you're using sprocs update it there
3. every time you update anything update the last update column.

i like 1. although for heavy insert/update db it can slow down performance (but not by much)

Go with the flow & have fun! Else fight the flow
Go to Top of Page

IT1
Starting Member

5 Posts

Posted - 2005-11-21 : 11:22:25
Cant you just use GETDATE() again in the update command to update the Last_updated field?

Default values are for new rows only I think.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-11-21 : 11:31:35
you think correctly

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-11-21 : 13:22:32
"it can slow down performance (but not by much)"

Do you reckon "but not by much" ??

We currently have AFTER triggers on all our tables to just fill in the Update Date and do a few checks. I think these are a waste of time, and that each INSERT is effectively done twice, and therefore my guess is that the trigger is quite "expensive" for this simple duty that could be jsut as esaily done in the Sprocs - but I'd be very happy for someone to tell me that in their experience this ain't the case, and it literally adds only a few percentage points to the individual insert.

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-21 : 13:37:13
Sproc only access to the database....becomes a non issue.



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-11-21 : 13:52:30
well yes i agree they're a waste of time.
but if you don't have 50 updates to the row per second you don't care about slow down that much, do you?
those 2 ms that it takes...
highly transactional table is a different story.


Go with the flow & have fun! Else fight the flow
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-11-21 : 14:09:25
"but if you don't have 50 updates to the row per second you don't care about slow down that much, do you?"

We don't insert much - to any particular table - but there again we have these type of Triggers on pretty much every table.

They gotta go I reckon.

Kristen
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-11-21 : 14:18:44
i agree there old chap...
but you can do that only if you design your app from the bottom up.
having an app and not being able to modify it is another matter...
then triggers are the only way.
of course the devs who "programmed" the app give the answer to a question
- why didn't you use sproc's?
- hmmm... that's a good question... what are sprocs?
- stored procedures
- oh that... well there's no way we could do our monumental lookup stuf, blah blah blah... with them.
- ok.... idiots...


Go with the flow & have fun! Else fight the flow
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-11-22 : 01:51:52
Yeah, my triggers are there for Belt&Braces, but I figure that the trousers can stay up by themselves now, and save the resources!

Kristen
Go to Top of Page
   

- Advertisement -