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