Solved

Can't update table 'activityinst' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

Posted on 2008-10-03
1
1,117 Views
Last Modified: 2012-05-05
Hi,
  i have a trigger in mssql like below

and we migrated it to mysql like this:
CREATE TRIGGER UPDATE_ACTIVITYINST AFTER UPDATE ON ACTIVITYINST FOR EACH ROW
BEGIN
    DECLARE id integer;
    set id= new.ID;
        UPDATE ACTIVITYINST SET STATETIME = GETDATE() WHERE ACTIVITYINST.ID = id;

END

but when i tried to test, i entered a new record to ACTIVITYINST table.
and again i tried to update one that row. iam getting "Can't update table 'activityinst' in stored function/trigger because it is already used by statement which invoked this stored function/trigger."
error.
please let me know where im doing worng and what to do.
please reply soon,it is very urgent
Regards
vijji
0
Comment
Question by:vijji_lakshmi
1 Comment
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 22639304
See here:

http://dev.mysql.com/doc/refman/5.1/en/create-trigger.html

Specifically:

----------------------------------------------------
You can refer to columns in the subject table (the table associated with the trigger) by using the aliases OLD and NEW. OLD.col_name refers to a column of an existing row before it is updated or deleted. NEW.col_name refers to the column of a new row to be inserted or an existing row after it is updated.
----------------------------------------------------

Also, you cannot use this in an AFTER trigger.   You'll need to use a BEFORE trigger for this strategy:

set new.STATETIME=GETDATE();
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Whether to use true/false, yes/no or 0/1 11 65
PHP: concatenate query 13 79
category table 2 30
Incorrect definition of table mysql.proc 7 45
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question