Mysql 建立時間和更新時間

2021-10-10 15:16:37 字數 1043 閱讀 4432

分三種情況

create table `mytest` (

`text` varchar(255) default '' comment '內容',

-- 直接指定建立時間和更新時間

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

`update_time` timestamp not null default current_timestamp on update current_timestamp comment '更新時間'

) engine=innodb default charset=utf8;

語法

-- 沒有欄位時,新增字段

alter table add `create_time` timestamp not null default current_timestamp comment '建立時間';

alter table add `update_time` timestamp not null default current_timestamp on update current_timestamp comment '更新時間';

示例

-- 沒有欄位時,新增字段
語法

alter table change create_time create_time timestamp not null default current_timestamp comment '建立時間';

alter table change update_time update_time timestamp not null default current_timestamp on update current_timestamp comment '更新時間';

示例

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

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

mysql更新時間 Mysql 更新時間

mysql時間加減函式為date add date sub 定義和用法 date add 函式向日期新增指定的時間間隔。date sub 函式向日期減少指定的時間間隔。語法date add date,interval expr type date sub date,interval expr typ...

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

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