错误#1109 - 触发器

时间:2015-07-02 07:29:05

标签: mysql phpmyadmin

这是我的触发器。

我想在1张桌子上制作扳机(pelayanan)。

CREATE DEFINER=`root`@`localhost` TRIGGER `before_insert_pelayanan` 
BEFORE INSERT ON `pelayanan` FOR EACH ROW 
IF NEW.`ESTIMASI` IS NULL OR NEW.`ESTIMASI` = 0 AND
    `dbhpl`.`pelayanan`.`DAYA` <= 5500 
    THEN SET NEW.ESTIMASI = 4; 
ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
    `dbhpl`.`pelayanan`.`DAYA` <= 33000 AND 
    `dbhpl`.`pelayanan`.`DAYA` >= 6600 
    THEN SET NEW.ESTIMASI = 15; 
ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
   `dbhpl`.`pelayanan`.`DAYA` <= 197000 AND 
   `dbhpl`.`pelayanan`.`DAYA` >= 41500 
    THEN SET NEW.ESTIMASI = 40; 
ELSE SET NEW.ESTIMASI = 100; 
END IF

当我执行触发器时,它已被创建。但是,当我将数据插入表pelayanan时,它变成了

  

#1109 - 未知的桌子&#39; pelayanan&#39;在字段列表中。

我该如何解决这个问题?

我必须删除dbhpl.pelayanan.DAYA成为pelayanan.DAYADAYA。但是,它没有用。

1 个答案:

答案 0 :(得分:0)

在列名前使用NEW。这是正确的代码 -

mysql>
    CREATE DEFINER=`root`@`localhost` TRIGGER `before_insert_pelayanan`
    BEFORE INSERT ON `pelayanan` FOR EACH ROW 
        IF NEW.`ESTIMASI` IS NULL OR NEW.`ESTIMASI` = 0 AND
            `NEW`.`DAYA` <= 5500 
            THEN SET NEW.ESTIMASI = 4; 
        ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
            `NEW`.`DAYA` <= 33000 AND 
            `NEW`.`DAYA` >= 6600 
            THEN SET NEW.ESTIMASI = 15; 
        ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
           `NEW`.`DAYA` <= 197000 AND 
           `NEW`.`DAYA` >= 41500 
            THEN SET NEW.ESTIMASI = 40; 
        ELSE SET NEW.ESTIMASI = 100; 
    END IF

Query OK, 0 rows affected (0.11 sec)

mysql> insert into pelayanan values ();
Query OK, 1 row affected (0.08 sec)

mysql> select * from pelayanan ;
+----------+------+
| ESTIMASI | daya |
+----------+------+
| 4        | NULL |
+----------+------+
1 row in set (0.00 sec)