MySQL对于create_time和update_time的处理

一 数据库建表SQL实例

create table print_ship_money_template (
	id int(11) primary key auto_increment comment "id",
    template_name varchar(200) not null comment "名称",
    eare varchar(200) not null comment "区域",
    ship_money int(11) not null comment "运费",
    create_time timestamp not null default CURRENT_TIMESTAMP comment "创建时间",
    update_time timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment "更新时间",
    version int(11) not null comment "最新版本号",
    del_flag tinyint not null comment "删除标记(0-否,1-是)"
    ) engine = Innodb default charset = utf8mb4 comment = "模板表";

如表所示

  • 对于create_time字段进行当前时间默认值设定:DEFAULT CURRENT_TIMESTAMP.
  • 对于update_time字段需要更新操作,所以设置为:ON UPDATE CURRENT_TIMESTAMP,既可以一直进行当前时间获取操作。

基于此实现,我们在数据库层面对字段create_time和update_time进行操作,而无需通过代码的来维护他们状态的变化。

待续...

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值