代码如下:
DELIMITER$
CREATE OR REPLACE TRIGGER tr_coupon AFTER INSERT OR DELETE ON coupon FOR EACH ROW
BEGIN
IF inserting THEN
DECLARE @i INT
SET @i=0
WHILE @i<:New.Nums DO
INSERT INTO coupondetail(Codes,CbeginDate,CendDate,IsGet,GetTime,CdIsUsed,Cp_ID,IsPutaway)
VALUES(rand_string(12),:New.BeginDate,:New.EndDate,0,,0,:New.Cp_ID,0)
SET @i=@i+1
END WHILE;
END IF; IF deleting THEN
DELETE FROM coupondetail WHERE coupondetail.`Cp_ID`=old.Cp_ID
END IF;
END$DESC coupon;别的不说 单单只运行“创建触发器”的命令就报错 更不用说下面的insert和delete了,报的错是:
1 queries executed, 0 success, 1 errors, 0 warnings查询:DELIMITER$ CREATE OR REPLACE TRIGGER tr_coupon AFTER INSERT OR DELETE ON coupon FOR EACH ROW BEGIN IF inserting THEN DECLARE @i ...错误代码: 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 'DELIMITER$
CREATE OR REPLACE TRIGGER tr_coupon AFTER INSERT OR DELETE ON coupon ' at line 1执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.002 sec请教各位大神:网上说是语法错误,小弟眼拙,请各位大神指教!!!
DELIMITER$
CREATE OR REPLACE TRIGGER tr_coupon AFTER INSERT OR DELETE ON coupon FOR EACH ROW
BEGIN
IF inserting THEN
DECLARE @i INT
SET @i=0
WHILE @i<:New.Nums DO
INSERT INTO coupondetail(Codes,CbeginDate,CendDate,IsGet,GetTime,CdIsUsed,Cp_ID,IsPutaway)
VALUES(rand_string(12),:New.BeginDate,:New.EndDate,0,,0,:New.Cp_ID,0)
SET @i=@i+1
END WHILE;
END IF; IF deleting THEN
DELETE FROM coupondetail WHERE coupondetail.`Cp_ID`=old.Cp_ID
END IF;
END$DESC coupon;别的不说 单单只运行“创建触发器”的命令就报错 更不用说下面的insert和delete了,报的错是:
1 queries executed, 0 success, 1 errors, 0 warnings查询:DELIMITER$ CREATE OR REPLACE TRIGGER tr_coupon AFTER INSERT OR DELETE ON coupon FOR EACH ROW BEGIN IF inserting THEN DECLARE @i ...错误代码: 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 'DELIMITER$
CREATE OR REPLACE TRIGGER tr_coupon AFTER INSERT OR DELETE ON coupon ' at line 1执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.002 sec请教各位大神:网上说是语法错误,小弟眼拙,请各位大神指教!!!
语法报错是在 delimiter, 而 delimiter 是 mysql 客户端工具支持,它不是 sql 语句,如果你不在 mysql 客户端工具中执行,那么不能用 delimiter
https://dev.mysql.com/doc/refman/5.7/en/create-trigger.html