Subject Re: [firebird-support] Maintaining count with trigger, prevent updating on cascades
Author Ann W. Harrison
sqlsvr wrote:
> I have two tables: blogs and blog posts. Blogs keep a count of blog posts and blog posts has a foreign key (cascade) to blogs. There is a trigger on blog posts that updates the count in blogs table.
>
> Now, if a blog post is inserted/deleted, I want to update the blogs count. However, if a blog is deleted....it will cascade the delete on the blog posts table.
>
> I'm assuming that this will cause the trigger to execute and update the blogs table unnecessarily? If so, is there anyway to stop it?

The cascading delete of the blog posts records happens after
the blog has been deleted, so the trigger will fire, find no
matching record, and stop.

Best regards,

Ann