1. MySQL
- 支持设置自增id的字段类型:int、bigint、double等数值类型,一般用int、bigint
- 支持设置自动更新时间的字段类型:datetime、timestamp
- 下面sql中的now()函数可以用current_timestamp()替代
1.1. 不指定秒精度
drop table if exists demo;
create table demo
(id         bigint auto_increment primary key       comment '自增id',name       varchar(8)                              comment '姓名',datetime1  datetime  default now()                 comment 'insert        时,更新时间',datetime2  datetime                on update now() comment '       update 时,更新时间',datetime3  datetime  default now() on update now() comment 'insert/update 时,更新时间',timestamp1 timestamp default now()                 comment 'insert        时,更新时间',timestamp2 timestamp               on update now() comment '       update 时,更新时间',timestamp3 timestamp default now() on update now() comment 'insert/update 时,更新时间'
) comment = '测试自动更新时间';1.2. 指定秒精度为3
 
drop table if exists demo;
create table demo
(id         bigint auto_increment primary key            comment '自增id',name       varchar(8)                                   comment '姓名',datetime1  datetime(3)  default now(3)                  comment 'insert        时,更新时间',datetime2  datetime(3)                 on update now(3) comment '       update 时,更新时间',datetime3  datetime(3)  default now(3) on update now(3) comment 'insert/update 时,更新时间',timestamp1 timestamp(3) default now(3)                  comment 'insert        时,更新时间',timestamp2 timestamp(3)                on update now(3) comment '       update 时,更新时间',timestamp3 timestamp(3) default now(3) on update now(3) comment 'insert/update 时,更新时间'
) comment = '测试自动更新时间';1.3. 测试

1.4. navicat
1.4.1. 自动更新时间

1.4.2. 自增Id

9.参考
MYsql 和Oracle 的时间类型字段自动更新