mysql trigger query. Is it correct? [duplicate]
Possible Duplicate:
Update mysql table on Insert command
Below is the query I am usi开发者_StackOverflow社区ng to insert a new row in send_sms table:
DELIMITER $$
CREATE TRIGGER before_insert;
BEFORE UPDATE ON send_sms
FOR EACH ROW BEGIN
INSERT INTO send_sms
(sender, receiver, msgdata)
VALUES
('123456', '654321', 'hello trigger')
END
DELIMITER ;
...before an Insert query is executed on send_sms table. Am I doing it right? Because I am not getting what I want.
The query is not working because there are syntax errors, here is the correct version
DELIMITER $$
CREATE TRIGGER after_insert -- remove ;
AFTER INSERT ON table_first
FOR EACH ROW BEGIN
INSERT INTO table_second
(value1, rvalue2, value3)
VALUES
('123456', '654321', 'hello trigger'); -- add ;
END
$$ -- add $$
DELIMITER ;
精彩评论