mysql5.6.4以下不支持多个字段类型为timestamp

原因说明:

One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.

 

但是创建时间和更新时间是每个表必须的,所以使用触发器解决:

delimiter $$
create trigger update_wh_order_trigger
BEFORE update on wh_order for each row
begin
set new.update_time = CURRENT_TIMESTAMP;
end;
$$;

建表语句:

create table wh_order(
id int(11) not null AUTO_INCREMENT COMMENT '系统编号',
order_no VARCHAR(64) DEFAULT '' COMMENT '订单编号',
order_name VARCHAR(200) DEFAULT '' COMMENT '订单名称',
order_price decimal(12,4) DEFAULT 0.0000 COMMENT '订单价格',
description VARCHAR(500) DEFAULT '' COMMENT '订单描述',
remark VARCHAR(500) DEFAULT '' COMMENT '备注',
user_code VARCHAR(64) DEFAULT '' COMMENT '用户编号',
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time datetime not NULL COMMENT '更新时间',
data_status VARCHAR(2) DEFAULT 'T' COMMENT '数据状态 T 有效 F 无效',
PRIMARY KEY(id)
) ENGINE = INNODB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8 COMMENT '订单表';

 

posted on 2018-02-04 20:24  _故乡的原风景  阅读(162)  评论(0编辑  收藏  举报