mysql 設計表 建立時間和更新時間 小技巧

2021-10-06 18:20:41 字數 761 閱讀 9746

關於自動更新時間,不用在開發的時候不用去自己手動插入時間,關於這個自動更新的事情還有個小插曲,首先我是知道關於這個小技巧的,可是但我想去設定的時候突然忘記領了,自己去網上搜了一下,真的是服氣,我估計有的人自己都沒有試過,直接複製貼上,這裡我放上自己關於時間處理的方法:

create table `demo` (

`id` int(10

) not null,

`create_time` timestamp not null default current_timestamp comment '建立時間'

, `update_time` timestamp not null default current_timestamp on update current_timestamp comment '修改時間'

, `enabled` varchar(10

) default null comment '是否啟動'

, `profile_photo` varchar(20

) default null comment '位址'

, primary key (`id`)

) engine=innodb default charset=utf8;

說一下:這裡其實建立時間和更新時間都是相同的預設值:

建立時間的:current_timestamp

更新時間的:current_timestamp

Mysql 建立時間和更新時間

分三種情況 create table mytest text varchar 255 default comment 內容 直接指定建立時間和更新時間 create time timestamp not null default current timestamp comment 建立時間 upda...

MySQL 設定 建立時間 和 更新時間

在實際應用中,我們時常會需要用到建立時間和更新時間這兩個字段,下面記錄一下 create table user info uid varchar 255 character set utf8 collate utf8 general ci not null,username varchar 255 ...

MySql建立時間及更新時間的智慧型更新

一條記錄一般會有建立時間跟更新時間 建立時間為第一次寫資料時填入,更新時間則記錄資料的最後修改時間 我們在資料庫設定了唯一索引,想基於唯一索引來批量插入更新資料,一般可以用replace 或者 on duplicate key replace的原理是先根據唯一索引檢查有無資料,沒有的插入,有的先刪除...