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
 Other Forums
 SQL Server 6.5 \ SQL Server 7.0
 For each row

Author  Topic 

medotnet
Starting Member

14 Posts

Posted - 2007-09-17 : 03:34:54
Hi all,

I made a trigger to fire on delete, but I have a problem that if multiples rows were deleted it malfunctions and operates only for one row.
I tried to use the deleted table and a while loop but didn't work..
any idea how to make the trigger work for each deleted row?

thanks in advance,

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 03:43:57
you need to code your trigger to handle sets and not row by row. The deleted table may contains more than one rows when your delete operations affected more than one rows.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

medotnet
Starting Member

14 Posts

Posted - 2007-09-17 : 03:51:20
How to handle sets?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 03:56:22
see http://weblogs.sqlteam.com/tarad/archive/2004/09/14/2077.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

medotnet
Starting Member

14 Posts

Posted - 2007-09-17 : 04:14:28
Well thanks, but I need a little help with the aliases, here the t1.somecolumn is not aliased nor the someColumn

CREATE TRIGGER trg_Table1
ON Table1
FOR UPDATE
AS

UPDATE t2
SET SomeColumn = t1.SomeColumn
FROM Table2 t2
INNER JOIN inserted i
ON t2.Table1_ID = i.Table1_ID

thanks,
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-17 : 04:20:39
[code]UPDATE t2
SET SomeColumn = i.SomeColumn
FROM Table2 t2
INNER JOIN inserted i
ON t2.Table1_ID = i.Table1_ID[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

medotnet
Starting Member

14 Posts

Posted - 2007-09-17 : 04:47:06
thanks a lot this is way better than @@RowCount
I appreciate it..
Go to Top of Page
   

- Advertisement -