在此中制作触发器的错误是什么?

时间:2014-12-02 18:14:33

标签: mysql phpmyadmin

我做了一个这样的触发器:

create trigger mytrigger 
before 
insert on
person4
for each row
begin
if new.salary < 5000 then
    set new.salary = 6000;
end if;
end;

这里的薪水是表人4的一个属性,我正在触发这个。但是,它显示错误:#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 '' at line 8

为什么会这样?语法完全正确。为什么会发生这种情况?

1 个答案:

答案 0 :(得分:1)

触发器看起来很好,唯一缺少的是分隔符。

我刚刚用样本表创建了一个triger,这里是

delimiter //
create trigger mytrigger before insert on person4
for each row
begin
 if new.salary < 5000 then
   set new.salary = 6000;
 end if;
end;//

delimiter;

这是mysql测试

mysql> create table person4(id int, name varchar(20),salary int);
Query OK, 0 rows affected (0.16 sec)

mysql> insert into person4 values (1,'aa',6000);
Query OK, 1 row affected (0.06 sec)
mysql> select * from person4;
+------+------+--------+
| id   | name | salary |
+------+------+--------+
|    1 | aa   |   6000 |
+------+------+--------+
1 row in set (0.01 sec)

mysql> insert into person4 values (1,'bb','3000');
Query OK, 1 row affected (0.04 sec)

mysql> select * from person4;
+------+------+--------+
| id   | name | salary |
+------+------+--------+
|    1 | aa   |   6000 |
|    1 | bb   |   6000 |
+------+------+--------+
2 rows in set (0.00 sec)