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)
 Update trigger question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-11-16 : 07:03:09
Ger writes "Hello there..

Little question,

I want to update a field(usr_date_modified) in a record in a table(tbl_user) with the date and time when this record has been modified.

I therefore want to use a n AFTER UPDATE trigger.
But when I use the trigger it updates that field in ALL records in that table instead of only the record that has been modified.

Could you please tell em what I am doing wrong? or forget?
The code I used is listed below.

Thanks in Advance
Ger Suverkropp

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER TRIGGER tr_aft_upd_tbluser
ON dbo.tbl_user
AFTER UPDATE

AS

UPDATE tbl_user
SET usr_date_modified=GETDATE()
WHERE usr_id=usr_id

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO"

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2004-11-16 : 10:00:35
[code]
UPDATE tbl_user
SET usr_date_modified=GETDATE()
WHERE usr_id in (select usr_id from inserted)
[/code]
Go to Top of Page

gesus
Starting Member

1 Post

Posted - 2004-11-18 : 06:40:11
quote:
Originally posted by LarsG


UPDATE tbl_user
SET usr_date_modified=GETDATE()
WHERE usr_id in (select usr_id from inserted)




Thanks a lot!
Works fine now..
Go to Top of Page
   

- Advertisement -