May 13, 2003 at 2:39 pm
guys,
have 2 tbls (1-M) relationship.
tblContact [PK contId(int 4), Name, MemoCount(int 4)]
tblMemo[pk memoId (int 4), {FK} contId(int 4), memo (varchar 100)]
I need to Write a trigger to automatically update the MemoCount field in the tblContact whenever a memo is inserted, updated or deleted. Assuming that the memoCount does not have the corect value, how would u write update trigger for that.
thanks
Edited by - mark00189 on 05/13/2003 2:40:59 PM
May 13, 2003 at 9:45 pm
I would think you would only change a count on insert or delete so here it is:
CREATE TRIGGER trgMemoCnt
ON tblMemo
FOR INSERT, DELETE
AS
if exists (select * from deleted)
begin
update tblContact set memocount = select (memocount - 1) from tblcontact
end
if exists (select * from inserted)
begin
update tblcontact set memocount = select (memocount + 1) from tblcontact
end
Darren
Darren
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply