Subject | Maintaining count with trigger, prevent updating on cascades |
---|---|
Author | sqlsvr |
Post date | 2010-07-15T01:46:10Z |
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?
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?