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

效果图


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM