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

    技术2022-07-13  73

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

    关键点:

    字段的数据类型为:timestamp null default current_timestamp on update current_timestamp插入记录的值为 default

    参考资料:

    MySQL 数据库自动获取当前时间(图形界面) MySQL插入数据时自动添加创建时间(create_time)和修改时间(update_time)

    实际案例:

    # 创建job密码表 use password; create table job( id int auto_increment primary key, name varchar(225), account varchar(225), password varchar(50), class text, update_time timestamp null default current_timestamp on update current_timestamp ); # 插入记录 insert into job values( null, '工号', 'X2001059', null, null, default); # 此处时间的记录为 default, 而不是 null select * from job;

    效果展示:

    Processed: 0.008, SQL: 9