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)
 Update trigger for multiple rows

Author  Topic 

amitfrd.iet
Starting Member

2 Posts

Posted - 2008-12-10 : 01:31:13
Update trigger for multiple rows
i have a update trigger that get fired when any column updated of the table


create TRIGGER trigger_Update_ABC
ON ABC
FOR Update
AS
declare @Id bigint
set @Id = (select Id from Inserted)
update ABC set ABC.Post = getdate() where Id =@Id




when i execute such sql quarry

Update ABC set ABC.Active = 1 where ABC.Id in(1,4,5,6,3,7)then i got error because of multiple row updation

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-10 : 01:37:57
http://weblogs.sqlteam.com/tarad/archive/2004/09/14/2077.aspx

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

Subscribe to my blog
Go to Top of Page

amitfrd.iet
Starting Member

2 Posts

Posted - 2008-12-10 : 02:00:35
than x its helps
but the my problem is i have to update sate table 's "Post"
column that updated with current getdate() function
so its call an infinite looping..
so how can i know that if the "Post" column update we do not fire this trigger
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-10 : 02:27:27
[code]create TRIGGER trigger_Update_ABC
ON ABC
FOR Update
AS

update a
set a.Post = getdate()
FROM ABC a
JOIN INSERTED i
ON i.Id =a.Id[/code]



Go to Top of Page
   

- Advertisement -