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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Triggers updating other tables

Author  Topic 

Ironwil
Starting Member

8 Posts

Posted - 2009-08-30 : 00:28:21
I'm setting up a blog database, and I have a comment count in a column in the blog item table. I want that value to be incremented each time a comment is made, and decremented each time a comment is deleted. I'd like to set this up as a trigger, but I don't know how. I've got the stub trigger set up:

CREATE TRIGGER [NewTrigger] ON [dbo.[BlogComment] AFTER INSERT, DELETE AS

GO

But what to put inside this, that is the question. Basically I was to grab the value of the CommentCount colmn from the BlogItem table, add/delete 1 to/from it, and set that value.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-08-30 : 01:02:14
Why are you storing the comment count in the first place? Wouldn't you instead just dynamically count the number of comments?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -