Solved

problem wtih trigger create

Posted on 2013-12-18
2
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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