This may be a stupid question but is it possible to store a count query in a field in a table such that when the result of the count changes the result will update itself?
Thread(ThreadID,NumMessages)
Message(MessageID,ThreadID,MessageText,PreviousMessage)
I want to update the Thread.NumMessages field any time a message with the corresponding ThreadID gets added or removed. I know I can do this by incrementing/decrementing the Thread.NumMessages field of by using a count query
SELECT COUNT(*), FROM SCHEMA.Message WHERE ThreadID='SOMETHREADID'
But is there anyway of setting up the NumMessages field so this is kept up to date without it being done explicitly at every addition and delete?
Thanks Graeme