免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2740 | 回复: 1
打印 上一主题 下一主题

有關triggers的問題 想請問 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-24 15:22 |只看该作者 |倒序浏览
想請問一下 我用下面的語法建立 trigger 但是有問題 可是我用query的ui卻又可以
原始的script(用console是不能執行的 \. *.sql 但是 用ui卻可以)
CREATE TRIGGER `tri_MailMeaasgeReadForward` AFTER UPDATE ON `mail_item`
FOR EACH ROW BEGIN
IF NEW.`unread` = 0 AND OLD.`unread` = 1 THEN UPDATE `mailstat`.`mail_index` SET `mail_index`.`read_datetime` = date_format(now(),'%Y-%m-%d %H-%i-%S') WHERE `mail_index`.`user_id` = NEW.`mailbox_id` AND `mail_index`.`mail_id` = NEW.`id`;END IF;
IF NEW.`flags` = 8 AND OLD.`flags` = 0 THEN UPDATE `mailstat`.`mail_index` SET `mail_index`.`forward_datetime` = date_format(now(),'%Y-%m-%d %H-%i-%S') WHERE `mail_index`.`user_id` = NEW.`mailbox_id` AND `mail_index`.`mail_id` = NEW.`id`;END IF;
END;

產生錯誤如下
mysql> CREATE TRIGGER `tri_MailMeaasgeReadForward` AFTER UPDATE ON `mail_item`   
-> FOR EACH ROW     
-> BEGIN   
-> IF NEW.`unread` = 0 AND OLD.`unread` = 1 THEN   
-> UPDATE `mailstat`.`mail_index` SET `mail_index`.`read_datetime` = date_format(now(),'%Y-%m-%d %H-%i-%S') WHERE `mail_index`.`user_id` = NEW.`mailbox_id` AND `mail_index`.`mail_id` = NEW.`id`;
ERROR 1064 (42000): 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 5
mysql> END IF;ERROR 1064 (42000): 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 'END IF' at line 1
mysql> IF NEW.`flags` = 8 AND OLD.`flags` = 0 THEN   
-> UPDATE `mailstat`.`mail_index` SET `mail_index`.`forward_datetime` = date_format(now(),'%Y-%m-%d %H-%i-%S') WHERE `mail_index`.`user_id` = NEW.`mailbox_id` AND `mail_index`.`mail_id` = NEW.`id`;ERROR 1064 (42000): 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 'IF NEW.`flags` = 8 AND OLD.`flags` = 0 THENUPDATE `mailstat`.`mail_index` SET `' at line 1mysql> END IF;ERROR 1064 (42000): 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 'END IF' at line 1mysql> END;ERROR 1064 (42000): 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 'END' at line 1

想請問 最原始的script應該如何改才是正確的

[[i] 本帖最后由 ieting 于 2008-1-24 15:26 编辑 [/i]]

论坛徽章:
0
2 [报告]
发表于 2008-01-27 19:42 |只看该作者
需要设置 DELIMITER,手册的例子有的吖。。。
例如:
DELIMITER // #这里把界定符改成 //
CREATE TRIGGER ....
....
END //

DELIMITER ; #这里再把界定符改回来
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP