I want to create a trigger after insert on one table which would insert values into another table based upon the values of the first table.Here is what i have done and its not working.
CREATE TRIGGER add_into_alerts
AFTER INSERT ON in_sims_responses
FOR EACH ROW
IF new.sim_response_code='102'
THEN
INSERT INTO bf_alters(company_id,description,event_datetime)
VALUES (NEW.sim_company_id,CONCAT(new.sim_msisdn,'Not Subscribed'),NOW());
END IF
For multiple-statements triggers you need to wrap your statements between BEGIN
and END
. But you can avoid that by making it a single-statement trigger. In your case you can use a conditional insert:
INSERT INTO bf_alters(company_id,description,event_datetime)
SELECT NEW.sim_company_id, CONCAT(new.sim_msisdn,'Not Subscribed'),NOW()
FROM dual
WHERE new.sim_response_code='102';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.