谢谢版主,我很受伤啊!!
在源表上执行失败。
我重新建了一个数据库,然后执行如下,成功了!但是接下来,就一直失败了,我的操作如下:
1、重新建库建表、建触发器:(成功)。
SQL code
CREATE DATABASE `ccc` ;
use ccc;
CREATE TABLE IF NOT EXISTS `wap_usermoniter` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL,
`uname` varchar(30) NOT NULL,
`type` varchar(5) NOT NULL,
`add` int(7) NOT NULL,
`now_value` int(8) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `uid` (`uid`,`uname`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `users_table` (
`uid` int(8) NOT NULL AUTO_INCREMENT,
`uname` varchar(10) NOT NULL,
`exper` int(8) NOT NULL,
`score` int(8) NOT NULL,
`gold` int(8) NOT NULL,
PRIMARY KEY (`uid`),
KEY `uname` (`uname`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- 转存表中的数据 `users_table`
--
INSERT INTO `users_table` VALUES (1, 'admin', 20, 30, 40);
delimiter //
create trigger `user_monitor` after update on `users_table`
for each row
BEGIN
DECLARE aa int(10);
DECLARE bb int(10);
DECLARE cc int(10);
set aa= New.exper - OLD.exper;
set bb= New.score - OLD.score;
set cc= New.gold - OLD.gold;
if NEW.exper>0 and aa<>0 then
INSERT INTO `wap_usermoniter` VALUES (NULL, OLD.uid, OLD.uname, 'exp', aa, NEW.exper, CURRENT_TIMESTAMP);
elseif NEW.score>0 and bb<>0 then
INSERT INTO `wap_usermoniter` VALUES (NULL, OLD.uid, OLD.uname, 'score',bb, NEW.score, CURRENT_TIMESTAMP);
elseif NEW.gold>0 and cc<>0 then
INSERT INTO `wap_usermoniter` VALUES (NULL, OLD.uid, OLD.uname, 'gold', cc, NEW.gold, CURRENT_TIMESTAMP);
end if;
END;
//
2、我删除触发器:(执行成功)
SQL code
drop TRIGGER user_monitor;
3、我随便执行一句错误的创建触发器指令:(失败)
SQL code
create trigger `user_monitor` after update on `users_table`;
4、我执行正确的创建触发器sql:(失败!):
SQL code
delimiter //
create trigger `user_monitor` after update on `users_table`
for each row
BEGIN
DECLARE aa int(10);
DECLARE bb int(10);
DECLARE cc int(10);
set aa= New.exper - OLD.exper;
set bb= New.score - OLD.score;
set cc= New.gold - OLD.gold;
if NEW.exper>0 and aa<>0 then
INSERT INTO `wap_usermoniter` VALUES (NULL, OLD.uid, OLD.uname, 'exp', aa, NEW.exper, CURRENT_TIMESTAMP);
elseif NEW.score>0 and bb<>0 then
INSERT INTO `wap_usermoniter` VALUES (NULL, OLD.uid, OLD.uname, 'score',bb, NEW.score, CURRENT_TIMESTAMP);
elseif NEW.gold>0 and cc<>0 then
INSERT INTO `wap_usermoniter` VALUES (NULL, OLD.uid, OLD.uname, 'gold', cc, NEW.gold, CURRENT_TIMESTAMP);
end if;
END;
//
求解失败的原因。我的另一个老库也因为此原因一直不能创建触发器。明明正确但就是不成功。
(ps.最后,在命令模式下,成功了。看来是phpmyadmin的问题,
以上测试是在phpMyAdmin 3.2.0-rc1 + mysql5.1.34-community平台) |