简体   繁体   English

MySql 未创建触发器。 语法错误:#1064

[英]MySql Trigger not created. Syntax error:#1064

i have a problem with trigger in MySql. When i create a trigger i have a syntax error我在 MySql 中遇到触发器问题。当我创建触发器时出现语法错误

 CREATE TABLE user (
 id int NOT NULL,
 completeName varchar(255) NOT NULL,
 email varchar(255) NOT NULL,
 passw_hash varchar(255) NOT NULL,
 accType varchar(255) NOT NULL,
 PRIMARY KEY (id)
 );
 create or REPLACE trigger test
 AFTER insert on user
 FOR EACH ROW
 BEGIN
 INSERT INTO `user` VALUES (1,'Pinco 
 Pallo','pinco@pallo','zinco','Owner');
 end;

Erorr:#1064错误:#1064

There are 2 errors in shown code.显示的代码中有 2 个错误。

  1. MySQL does not support OR REPLACE in CREATE TRIGGER . MySQL 不支持CREATE TRIGGER中的OR REPLACE

It allows to use CREATE TRIGGER IF NOT EXISTS which forbids the trigger creation if it exists already.它允许使用CREATE TRIGGER IF NOT EXISTS ,如果它已经存在则禁止创建触发器。 If you want to replace trigger then you must drop it then recreate.如果你想替换触发器,那么你必须删除它然后重新创建。

https://dev.mysql.com/doc/refman/8.0/en/create-trigger.html https://dev.mysql.com/doc/refman/8.0/en/drop-trigger.html https://dev.mysql.com/doc/refman/8.0/en/create-trigger.html https://dev.mysql.com/doc/refman/8.0/en/drop-trigger.8674786

  1. Trigger cannot alter the table which it is defined on.触发器无法更改定义它的表。

Trigger will be created.触发器将被创建。 But it will cause Can't update table 'user' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.但它会导致无法更新存储函数/触发器中的表“用户”,因为它已被调用此存储函数/触发器的语句使用。 runtime error.运行时错误。

https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM