0

I called update query from table1 trigger, when that query runs, it updates other table2 successfully but update trigger of table2 is fired only 1 time means not for every record that was updated from query of update

I'm using SQL Server 2008 Express edition-

Please guide me where I am wrong

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ovais
  • 41
  • 5
  • 1
    Can you provide more information, You code, table structure – Markov Sep 28 '18 at 16:03
  • A trigger is called once for each UPDATE, INSERT or DELETE command, for all the records that are affected. The virtual tables INSERTED and DELETED will have multiple records if multiple records are affected by the command. – David Dubois Sep 29 '18 at 01:35
  • I have showed my first update trigger in answer, where u can see that, update query runs successfully and updating all records as expected but update trigger of 2table is not fired for all records except the first record. – Ovais Sep 29 '18 at 04:27
  • Markov, I have posted 2nd answer in which i have achieved my desire result by using cursor instead of update query in trigger. every thing is working fine. but the problem is that i dont want to use cursor thats y i replace my cursor to set based approach of update query. – Ovais Sep 29 '18 at 04:33
  • @DavidDubois, as u said trigger called once for each update command, you mean, not for all rows which was updating by update query? because you know that sql is set based approach, multiple record can be updated once by a single command. – Ovais Sep 29 '18 at 04:38
  • In short, Mass update can fire trigger for every row? :/ – Ovais Sep 29 '18 at 05:43

1 Answers1

2

Finally got the answer,

Trigger fire once for single query execution. mass or bulk update/insert/delete will not awake trigger for every row

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ovais
  • 41
  • 5