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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 update triger

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2006-06-27 : 15:27:03
I have two tables:

mater

Ticket_id status
1 created


detail
-----
Id ticket_id status
1 1 created
2 1 Add <--- Insert new record, fire trigger update the master table.
3 1 comment <-- Shouldn't fired trigger because status = 'Comment'




I would like to create a triger on detail table.

I would like to make the trigger got fired whenever there is INSERT ( where status <> 'comment') in the detail table , then update 'status' column in the master table.

How can I do tthis? can you show me some code example?



samuelclay
Yak Posting Veteran

71 Posts

Posted - 2006-06-27 : 16:25:19
hmm.. maybe something like this? books online has several similar examples..

CREATE TRIGGER trg_UpdateMasterStatusOnStatusChange ON dbo.Detail
FOR INSERT
AS
/* ---------------------------------------------------------------------------------
-- Purpose : Update status on master table when inserted record status <> 'comment'
-- --------------------------------------------------------------------------------- */
UPDATE master
SET status = i.status
FROM inserted i
WHERE master.Ticked_id = i.ticket_id
AND i.status <> 'comment'

Go to Top of Page
   

- Advertisement -