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 2005 Forums
 Transact-SQL (2005)
 Trigger update

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2010-04-01 : 16:25:47
All,

I have the following trigger which is built to update date_time_mod whenever an update is fired on the table, however the trigger is updating the date_time_mod of the first row only when a mass update is fired. Is there anyway to get around to update the date_time_mod for all the rows effected by the mass update statement.

ALTER TRIGGER [dbo].[TRG_table_DT_MOD]
ON [dbo].[table]
AFTER INSERT, UPDATE
NOT FOR REPLICATION
AS
BEGIN

SET NOCOUNT ON
IF TRIGGER_NESTLEVEL() > 1
RETURN

declare @table_id bigint

select @table_id=table_id from INSERTED


UPDATE table
SET DATE_TIME_MOD = GETDATE() WHERE table_id = @table_id
end

GO

below is the mass update statement which effects 200 rows but the date_time_mod is updated only for the first row.

update table
set user_id = user_id

Any suggestions and inputs would help.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-01 : 16:34:04
See this: http://weblogs.sqlteam.com/tarad/archive/2004/09/14/2077.aspx

The example UPDATE statement for multiple rows should help you come up with a solution.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2010-04-01 : 16:48:04
quote:
Originally posted by tkizer

See this: http://weblogs.sqlteam.com/tarad/archive/2004/09/14/2077.aspx

The example UPDATE statement for multiple rows should help you come up with a solution.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



Thanks that did the trick.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-01 : 17:00:44
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -