Solved

problem wtih trigger create

Posted on 2013-12-18
2
312 Views
Last Modified: 2013-12-19
hello i have trigger

DELIMITER |

CREATE TRIGGER controlit AFTER INSERT ON

  tblregistros_buffer
  FOR EACH ROW BEGIN
    IF NEW.buffer  between 0 and 33 THEN

      update tblregistros_buffer SET NEW.idcolor=2;

END IF;
 END
|

DELIMITER ;



but after of insert show

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

controlit  is database
tblregistros_buffer is table

i need that when i insert records in table tblregistros_buffer, save in column idcolor=2 with condition if

idcolor and buffer are of tblregistros_buffer
0
Comment
Question by:controlit
2 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 500 total points
ID: 39727918
- Make it a BEFORE instead of AFTER
- Don't use the UPDATE syntax, just a simple SET
DELIMITER |
CREATE TRIGGER controlit BEFORE INSERT ON tblregistros_buffer
FOR EACH ROW 
BEGIN
    IF NEW.buffer  between 0 and 33 THEN
      SET NEW.idcolor=2;
    END IF;
 END|

DELIMITER ;

Open in new window

0
 

Author Closing Comment

by:controlit
ID: 39729035
and the answers should be, clear and perfect short
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Creating and Managing Databases with phpMyAdmin in cPanel.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now