提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
在Mysql中进行新建数据表时避免不了会有时间字段,一般表中都会包含create_time及update_time字段。
一、举个栗子
建表sql如下,
create table test (
//..省略部分字段
create_time datetime default **current_timestamp** not null,
update_time datetime default current_timestamp not null on update current_timestamp
)
-current_timestamp作用:数据创建时时间字段将插入为当前时间。
- on update current_timestamp作用:数据库进行更新操作时,只有当字段的值发生了变化时,被修饰的时间字段update_time才会更新为当前时间。