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 |
|
amarundo
Starting Member
9 Posts |
Posted - 2012-02-07 : 13:54:25
|
| Hi,I'm a newbie... I created the following trigger:[StampUpdate_TMP_TEST_LIST] on [dbo].[TMP_TEST_LIST]AFTER UPDATE AS UPDATE TMP_TEST_LIST SET RecordUpdatedOn = getdate()Because I want to know when was the last time a record was updated.The problem is that it's updating the whole table!!!Of course I know that generally speaking you need a WHERE clause, but I thought that a trigger would be different.The question is, how do I make the trigger update the RecordUpdatedOn column just for the record being updated? How can I give it a WHERE clause if I don't know how the UPDATE is happening?Thanks! |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
amarundo
Starting Member
9 Posts |
Posted - 2012-02-08 : 12:02:42
|
| Hi Brett,It's giving me an error. I'm running this script:ALTER TRIGGER[StampUpdate_TMP_TEST_CALL_LIST] on [dbo].[TMP_TEST_CALL_LIST]AFTER UPDATE AS UPDATE ttt SET RecordUpdatedOn = getdate() FROM [dbo].[TMP_TEST_CALL_LIST] ttt JOIN inserted iii ON ttt.key = iii.keyAnd the error is Msg 156, Level 15, State 1, Procedure StampUpdate_TMP_TEST_CALL_LIST, Line 8Incorrect syntax near the keyword 'key'.This is MS SQL 2005.Thanks!!! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
amarundo
Starting Member
9 Posts |
Posted - 2012-02-09 : 09:58:20
|
| oh, got it. I thought "key" was something internal in SQL. Yes, I do have a column that uniquely identified the record.Will test. Thanks.(I told you I'm a newbie...) |
 |
|
|
amarundo
Starting Member
9 Posts |
Posted - 2012-02-09 : 11:55:47
|
| Hey Brett,I worked (something tells me you are not surprised...)Thanks for your patience, man.- A |
 |
|
|
|
|
|
|
|