How can I get a trigger to fire on each inserted row during an INSERT INTO Table (etc) SELECT * FROM Table2?

后端 未结 2 1241
陌清茗
陌清茗 2020-12-02 00:44

I\'ve been trying to avoid using a cursor in this particular case just because I dislike the tradeoffs, and it just so happens a process I\'m using makes triggers look like

2条回答
  •  我在风中等你
    2020-12-02 01:04

    If you are sending an email, I would not do that from a trigger. Do you really want people to not be able to insert records because the email server is down?

    It is usually better to insert the records to a table from the trigger and then have a job that sends the emails that runs every minute or so and updates the email status to sent and adds the sent datetime to the table when each record is sent. This not only allows you to insert records when emails are down, it moves the looping to send each individual email to a table the users are not accessing (and thus any delay processing many records will only affect the new users not anyone else) and it allows you to see a history of when you sent the email which helps when people question why they didn't get it. You can also record in the table if the email failed to send to help identify bad email addresses.

提交回复
热议问题