【发布时间】:2012-11-24 13:30:54
【问题描述】:
从这样的 MySQL 触发器开始:
delimiter #
create trigger comments_after_ins_trig after insert on comments
for each row
begin
insert into comment_types (comment, user_id) values (new.comment, new.user_id);
end#
假设我想将插入内容拆分到不同的表中,例如,如果评论包含粗俗词 (LOCATE('sh**', comment) > 0),而不是 comment_types,我想插入名为 vulgar_cmets 的表中,如果评论包含“谢谢” " 或 "nice" 插入 nice_cmets 等。基本上如何使表名插入到该触发器的变量中?
【问题讨论】:
-
我知道如果,但我不能去
insert into if(LOCATE('sh**', comment) > 0, "vulgar_comments", "comment_types") (comment, user_id) values (new.comment, new.user_id); -
如何在“comment_types”中添加一列,其中包含……嗯……评论类型? IE 1 = 好,2 = 不太好,3 = 平均等等。
-
最初是这样写的,但现在需要将它们分开。不幸的是,视图也不可能。