处用MYSQL,麻烦大家帮我看看这个简单的触发器问题

Z8157522 2010-07-15 05:20:12
用的MYSQL 5.0
想吧表中某值的旧值和新值差加到另一张表中的某个字段中去。//这一步还没写到,麻烦有心人给个提示
但是写触发器的时候总是报错。不知道为什么。请大家帮忙看看。
一下两段代码都只是先写出来做下测试的,但是有问题。
CREATE TRIGGER update_position
AFTER UPDATE on position_tb FOR EACH ROW
BEGIN
IF (NEW.score <> OLD.score) THEN SELECT * FROM position_tb;
ELSE
SELECT * FROM class_tb;
END IF;
END;

错误:
Error Code : 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 'SELECT * FROM position_tb' at line 4
(0 ms taken)

Error Code : 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 'ELSE
SELECT * FROM class_tb' at line 1
(0 ms taken)

Error Code : 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 'END IF' at line 1
(0 ms taken)

Error Code : 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 'END' at line 1
(0 ms taken)

CREATE TRIGGER update_position
AFTER UPDATE on position_tb FOR EACH ROW
BEGIN
select * from position_tb;
END;

错误:
Error Code : 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 'select * from position_tb' at line 4
(0 ms taken)

Error Code : 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 'END' at line 1
(0 ms taken)
...全文
70 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2010-07-15
  • 打赏
  • 举报
回复
看一下手册中的基础教程部分。

MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
Z8157522 2010-07-15
  • 打赏
  • 举报
回复
比如说我在这张表(position_tb)中有一个人员ID和score字段,当该表score字段更新值的时候,同时把差值加到另一张表(personalinfo_tb)表的level字段上。
zuoxingyu 2010-07-15
  • 打赏
  • 举报
回复
首先把语法弄清楚。然后多动手测试,实在不行再来问。
Z8157522 2010-07-15
  • 打赏
  • 举报
回复
是把这个差值,与另一个表,比如personalinfo表中的score字段相加。

能告诉我我之前那样写的语句为什么会报错吗?
wwwwb 2010-07-15
  • 打赏
  • 举报
回复
CREATE TRIGGER update_position
AFTER UPDATE on position_tb FOR EACH ROW
BEGIN
IF (NEW.score <> OLD.score) THEN
insert into position_tb SELECT *,NEW.score -OLD.score FROM position_tb;
ELSE
insert into position_tb SELECT * FROM class_tb;
END IF;
END;
wwwwb 2010-07-15
  • 打赏
  • 举报
回复
你要达到什么目的?

57,062

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧