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)
 AFTER Trigger

Author  Topic 

kumar7704
Starting Member

4 Posts

Posted - 2005-04-01 : 08:51:48
I have table 'REQUEST'

REQUEST(REQ_ID,REQ_START_DATE,REQ_INITIATOR_ID,REQ_IMPLEMENTOR_ID,REQ_VERIFIER_ID,REQ_NEW_ID)

Everytime a new record is inserted into REQUEST I want to check if user REQ_NEW_ID if it is null I want to copy REQ_ID into REQ_NEW_ID..to acheive this I want to write a
AFTER Trigger,

CREATE TRIGGER myTrig
AFTER INSERT ON REQUEST
BEGIN
IF(REQ_NEW_ID is null)
UPDATE REQUEST SET REQ_NEW_ID = :NEW.REQ_ID
END;

But I get an error saying that trigger is trying to modify the mutating record, what does this mean? How can I fix this trigger..

rfrancisco
Yak Posting Veteran

95 Posts

Posted - 2005-04-01 : 09:40:22
Looking at your syntax, it looks like your trigger is for Oracle and not SQL Server. If you are working with SQL Server, try this one:

CREATE TRIGGER myTrig
AFTER INSERT ON REQUEST
BEGIN

UPDATE A
SET REQ_NEW_ID = ISNULL(A.REQ_NEW_ID, A.REQ_ID)
FROM REQUEST A INNER JOIN INSERTED B
ON A.REQ_ID = B.REQ_ID

END;
Go to Top of Page
   

- Advertisement -