SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


mutation in Trigger


mutation in Trigger

Author
Message
Minnu
Minnu
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1349 Visits: 950
Hi Team,

Am a sql developer and new to oracle, i was assinged a trigger for

am having two tables

Table1 : Test
Cols : ID | DESC

Table2: TEST_CUST
Cols : MID | STATUS

and i want a update in third table "S_ID" when an insert | Delete | Udpate happends on Table1.

Table3 : SID
Cols : M_ID | STATUS

CREATE OR REPLACE TRIGGER TRG_TEST
AFTER INSERT OR UPDATE OR DELETE
OF ID,DESC
ON TEST
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN

UPDATE S_ID SET STATUS ='Y'
WHERE SID in
(SELECT SID FROM TEST_CUST WHERE M_ID=:old."ID");

END;


--
But am gettting error "A mutation table is defined as a table that is changing"

need your help please...
Lowell
Lowell
SSC Guru
SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)

Group: General Forum Members
Points: 70980 Visits: 40924
your trigger is on the table TEST, but the update command is looking at a different table;

UPDATE S_ID SET STATUS ='Y'
WHERE SID in
(SELECT SID FROM TEST_CUST WHERE M_ID=:old."ID");


shouldn't that be TEST and not TEST_CUST?
otehrwise, you need to join TEST to TEST_CUST, and update SID from that combined results.

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Minnu
Minnu
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1349 Visits: 950
My requirement is when ever any insert|update|delete happens on Table1:Test,
then it should check the ID value in table SID, if ID is avaiale then update the column "status" to Y

can u please help in providing the query...
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search