mysql 触发器相关解决思路

mysql 触发器相关


chat_content 聊天记录

chat_content_id 所属id号 int(11) 非空 主键自增长

from_id 发送方id int(11) 非空

to_id 接收方id int(11) 非空

content 聊天数据 text 默认null

chat_time 发送时间 datetime 可空 由触发器更新

建表:

SQL code


  
create table chat_content
(
   chat_content_id                int(11)                        not null AUTO_INCREMENT,
   from_id                        int(11)                        not null,
   to_id                          int(11)                        not null,
   content                        text                           default NULL,
   chat_time                      datetime,
   primary key (chat_content_id),
}


触发器 – – 可惜是错的 求改正

SQL code


  
/*==============================================================*/
/* TRIGGER: chat_content_trig       chat_content   insert用     */
/*==============================================================*/
CREATE TRIGGER chat_content_trig after insert
ON chat_content FOR EACH ROW 

BEGIN
    update chat_content set chat_time =(select sysdate()) 
        where chat_content_id=new.chat_content_id
END;

– -在第5行 也就是end那 出错 纠结了呀 

我期望就是 在向表内插入数据后 该表的chat_time由触发器更新为系统时间



提示很清楚啊,AFTER之后,是不允许你对字段再进行修改了。 你应该在BEFORE触发器中。

mysql 触发器相关解决思路

相关文章:

你感兴趣的文章:

标签云: