mysql -h $host -u $user -p$pass $database -e "Create trigger trgQueuedSms
AFTER DELETE ON tblSmsQueue
FOR EACH ROW
BEGIN
DECLARE VALUE INTEGER;
SET value := (SELECT SUBSTRING_INDEX(USER(),'@',1)='user') ;
IF (value > 0)
THEN
INSERT INTO tblSmsQueueArchive(iID, sMsgId, sUserName, sResellerName,sDistributorName, sMsgText, sType, sSender, sDestination, bDlr, dtLoggedTime, iJobId, sFailReason) VALUES (old.iID, old.sMsgId, old.sUserName, old.sResellerName,old.sDistributorName,old.sMsgText, old.sType, old.sSender, old.sDestination, old.bDlr, NOW(), old.iJobId, 'DELETED');
END IF;
END;"
答案 0 :(得分:0)
由于你的触发器定义中有分号,你应该声明DELIMITER
不是分号,而是在DELIMITER
之后使用END
。例如,您可以使用$$
作为DELIMITER
,如下所示:
mysql -h $host -u $user -p$pass $database --delimiter="$$" -e "Create trigger trgQueuedSms
AFTER DELETE ON tblSmsQueue
FOR EACH ROW
BEGIN
DECLARE VALUE INTEGER;
SET value := (SELECT SUBSTRING_INDEX(USER(),'@',1)='user') ;
IF (value > 0)
THEN
INSERT INTO tblSmsQueueArchive(iID, sMsgId, sUserName, sResellerName,sDistributorName, sMsgText, sType, sSender, sDestination, bDlr, dtLoggedTime, iJobId, sFailReason)
VALUES (old.iID, old.sMsgId, old.sUserName, old.sResellerName,old.sDistributorName,old.sMsgText, old.sType, old.sSender, old.sDestination, old.bDlr, NOW(), old.iJobId, 'DELETED');
END IF;
END $$"