首先在创建表的时候
create table testmysqltime(
-> id int primary key auto_increment comment '主键id',
-> username varchar(10) not null comment '用户名',
-> password varchar(10) not null comment '用户密码',
-> createtime timestamp not null default current_timestamp comment '创建时间',
-> updatetime timestamp not null default current_timestamp on update current_timestamp comment '更新时间') comment '测试时间表';
在插入数据的时候 :
insert into testmysqltime (username, password) values ("admin", "123456");
这样我们在操作新增数据的时候 就不用考虑关于数据创建的时间的问题了。
在更新数据的时候
update testmysqltime set password="456789" where id=1;
这样我们在操作更新数据的时候 就不用考虑关于数据创建的时间的问题了。
注意的是:同一数据多次更改 更改的数据是相同的 那 更新的时间是不变化的
例如:update testmysqltime set password="456789" where id=1; 执行多次 更新时间还是第一次执行的时候的更新时间,除非你更改数据 把password="4567890"进行更改 在执行 更新时间就是当前时间了