MySQL觸發器 Update觸發Insert失敗

來源:互聯網
上載者:User

MySQL觸發器 Update觸發Insert失敗

今天工作需要,想要實現將僅對狀態更新的表進行記錄顯示,於是考慮在原表中建立觸發器,將更新的內容同時寫入另一張表

於是進行測試

 
--建立測試表
CREATE TABLE `triggletest_triggle` ( `id` INT(11) NOT NULL, `name` VARCHAR(5) NULL DEFAULT NULL, PRIMARY KEY (`id`))COLLATE='latin1_swedish_ci'ENGINE=InnoDB
  
--建立目標表CREATE TABLE `triggletest` (    `seq` INT(11) NOT NULL,    `id` INT(11) NOT NULL,    `name` VARCHAR(5) NULL DEFAULT NULL,    PRIMARY KEY (`seq`),    INDEX `id` (`id`))COLLATE='latin1_swedish_ci'ENGINE=InnoDB;
 
---寫入測試資料INSERT INTO `triggletest_triggle` VALUES(1,'A');
 
--建立觸發器DROP TRIGGER if EXISTS test1CREATE TRIGGER test1 AFTER UPDATE ON triggletest_triggleFOR EACH ROWBEGIN    INSERT INTO triggletest(id) values (new.id);END

執行觸發器語句,報錯,報錯內容如下:

/* SQL錯誤(1064):You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TRIGGER test1
AFTER UPDATE ON triggletest_triggle
FOR EACH ROW
BEGIN ' at line 2 */

問題待查

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.