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 |  
                                    | medotnetStarting 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, |  |  
                                    | khtanIn (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]
 |  
                                          |  |  |  
                                    | medotnetStarting Member
 
 
                                    14 Posts | 
                                        
                                          |  Posted - 2007-09-17 : 03:51:20 
 |  
                                          | How to handle sets? |  
                                          |  |  |  
                                    | khtanIn (Som, Ni, Yak)
 
 
                                    17689 Posts |  |  
                                    | medotnetStarting 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 someColumnCREATE TRIGGER trg_Table1ON Table1FOR UPDATEASUPDATE t2SET SomeColumn = t1.SomeColumnFROM Table2 t2INNER JOIN inserted iON t2.Table1_ID = i.Table1_IDthanks, |  
                                          |  |  |  
                                    | khtanIn (Som, Ni, Yak)
 
 
                                    17689 Posts | 
                                        
                                          |  Posted - 2007-09-17 : 04:20:39 
 |  
                                          | [code]UPDATE t2SET   SomeColumn = i.SomeColumnFROM  Table2 t2INNER JOIN inserted iON    t2.Table1_ID = i.Table1_ID[/code] KH[spoiler]Time is always against us[/spoiler]
 |  
                                          |  |  |  
                                    | medotnetStarting Member
 
 
                                    14 Posts | 
                                        
                                          |  Posted - 2007-09-17 : 04:47:06 
 |  
                                          | thanks a lot this is way better than @@RowCountI appreciate it..   |  
                                          |  |  |  
                                |  |  |  |