我想創建一個觸發器,使:MySQL錯誤1054:在字段列表中未知列「量」
- 如果金額字段< 100金額字段自動插入100
- 如果量> 100輸入的值應該插入到AMOUNT字段中。
表:
CREATE TABLE DB_triggers.acc(
C_ID INT(3) UNIQUE NOT NULL AUTO_INCREMENT ,
customer_name CHAR(30),amount FLOAT(10,2) UNSIGNED,
date_created DATE,PRIMARY KEY(C_ID,customer_name)
) AUTO_INCREMENT=100;
觸發:
DELIMITER $$
CREATE TRIGGER trig_acc
BEFORE INSERT ON acc
FOR EACH ROW
BEGIN
IF amount <100 THEN
INSERT INTO acc VALUES(new.c_id,new.customer_name,100,new.now());
ELSE
INSERT INTO acc VALUES(new.c_id,new.customer_name,new.amount,new.now());
END IF;
END $$
DELIMITER ;
但是,當我插入值:
INSERT INTO
acc(c_id,customer_name,amount,date_created)
VALUES
(DEFAULT,'ABC',1000,NOW());
給出錯誤1054
什麼時候會發生量會正好是100? –