1.MySQL
- 支持的字段类型:DATETIME、TIMESTAMP
drop table if exists test_time_auto_update;
create table test_time_auto_update
(
id bigint auto_increment primary key comment '自增id',
name varchar(8) comment '姓名',
datetime1 datetime default current_timestamp comment 'insert 时,更新时间',
datetime2 datetime on update current_timestamp comment ' update 时,更新时间',
datetime3 datetime default current_timestamp on update current_timestamp comment 'insert/update 时,更新时间',
timestamp1 timestamp default current_timestamp comment 'insert 时,更新时间',
timestamp2 timestamp on update current_timestamp comment ' update 时,更新时间',
timestamp3 timestamp default current_timestamp on update current_timestamp comment 'insert/update 时,更新时间'
) comment = '测试自动更新时间';
参考
MYsql 和Oracle 的时间类型字段自动更新