开发者

mysql trigger query. Is it correct? [duplicate]

This question already has an answer here: Closed 11 years ago.

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 ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜