MySQL插入数据时自动添加修改时间

create table t_user(
 user_id int primary key auto_increment, # 主键id
    username varchar(20) not null unique, # 用户名
    email varchar(30) not null unique, # 邮箱
    password varchar(20) not null, # 密码
    mobile varchar(20) not null, # 手机号
    role varchar(20) not null, # 身份
    status int not null, # 状态
    create_time datetime, # 创建时间
    # 更新时间  只要表中有一个字段更新此字段(update_time)更新
    update_time timestamp null default current_timestamp on update current_timestamp 
)

SELECT * from t_user

INSERT into t_user VALUES(null,'aaa','123@qq.com','123456','123123','普通用户',1,NOW(),DEFAULT)
INSERT into t_user VALUES(null,'bbb','456@qq.com','123456','123123','普通用户',1,NOW(),DEFAULT)
INSERT into t_user VALUES(null,'ccc','798@qq.com','123456','123123','普通用户',1,NOW(),DEFAULT)

update t_user set username='xiaohong' where user_id=1

效果图

posted @ 2020-12-27 11:09  花红  阅读(912)  评论(0编辑  收藏  举报