MySQL觸發器 Update觸發Insert掉敗。本站提示廣大學習愛好者:(MySQL觸發器 Update觸發Insert掉敗)文章只能為提供參考,不一定能成為您想要的結果。以下是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 test1 CREATE TRIGGER test1 AFTER UPDATE ON triggletest_triggle FOR EACH ROW BEGIN 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 */ ---終究完成代碼 DROP TRIGGER if EXISTS test1; CREATE TRIGGER test1 AFTER UPDATE ON test.triggletest_triggle FOR EACH ROW BEGIN INSERT INTO triggletest(id,name) values (new.id,new.name); END;
剖析,因為拜訪對象HediSQL,招致沒法正常創立觸發器,雷同語句,在HediSQL中履行,報錯,應用shell挪用mysql,直接履行法式,勝利。