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.
| Author |
Topic |
|
loamguy
Starting Member
15 Posts |
Posted - 2008-03-10 : 11:44:53
|
| I have a reference table that currently has no web front-end. It's a small table(<10 rows) that's not going to change very often (maybe once every few months).We manually update rows on the table via the GUI table interface in Enterprise Mgr., not in T-SQL. What I'd like to do is have SQL Server automatically update the "Last_Modified" column with the current timestamp. I can do it on an Insert using the GetDate() function, but if I update a row, this doesn't work.Is there a function I can use that can auto-populate for both insert and updates? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-10 : 11:48:51
|
Create a trigger. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
loamguy
Starting Member
15 Posts |
Posted - 2008-03-10 : 11:59:23
|
Thanks for the quick reply.I'll need to look into these "triggers." |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-10 : 15:38:49
|
CREATE TRIGGER trgMyDate ON MyTableAFTER UPDATE, INSERTASUPDATE tSET t.MyDateCol = GETDATE()FROM MyTable AS tINNER JOIN inserted AS i ON i.MyPkCol = t.MyPkCol E 12°55'05.25"N 56°04'39.16" |
 |
|
|
loamguy
Starting Member
15 Posts |
Posted - 2008-03-10 : 15:42:06
|
Awesome. Thanks a lot!! |
 |
|
|
|
|
|