mysql5.6.4以下不支持多个字段类型为timestamp
原因說(shuō)明:
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.
?
但是創(chuàng)建時(shí)間和更新時(shí)間是每個(gè)表必須的,所以使用觸發(fā)器解決:
delimiter $$
create trigger update_wh_order_trigger
BEFORE update on wh_order for each row
begin
set new.update_time = CURRENT_TIMESTAMP;
end;
$$;
建表語(yǔ)句:
create table wh_order(
id int(11) not null AUTO_INCREMENT COMMENT '系統(tǒng)編號(hào)',
order_no VARCHAR(64) DEFAULT '' COMMENT '訂單編號(hào)',
order_name VARCHAR(200) DEFAULT '' COMMENT '訂單名稱',
order_price decimal(12,4) DEFAULT 0.0000 COMMENT '訂單價(jià)格',
description VARCHAR(500) DEFAULT '' COMMENT '訂單描述',
remark VARCHAR(500) DEFAULT '' COMMENT '備注',
user_code VARCHAR(64) DEFAULT '' COMMENT '用戶編號(hào)',
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '添加時(shí)間',
update_time datetime not NULL COMMENT '更新時(shí)間',
data_status VARCHAR(2) DEFAULT 'T' COMMENT '數(shù)據(jù)狀態(tài) T 有效 F 無(wú)效',
PRIMARY KEY(id)
) ENGINE = INNODB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8 COMMENT '訂單表';
?
轉(zhuǎn)載于:https://www.cnblogs.com/hy87/p/8414187.html
總結(jié)
以上是生活随笔為你收集整理的mysql5.6.4以下不支持多个字段类型为timestamp的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 数据结构与算法(3)-----队列和栈
- 下一篇: linux cmake编译源码,linu