MySQLTIMESTAMP 時間戳 詳解

2021-12-29 22:28:37 字數 900 閱讀 2569

在建立表時如果表中有乙個字段型別為timestamp,則該字段預設的生成語句為:

create table `test` (

`id` int(11) default null,

`ctime` timestamp not null default current_timestamp on update current_timestamp

) engine=innodb default charset=gbk如果有兩個字段型別為timestamp,則生成語句為:

create table `test` (

`id` int(11) default null,

`ctime` timestamp not null default current_timestamp on update current_timestamp,

`utime` timestamp not null default '0000-00-00 00:00:00'

) engine=innodb default charset=gbktimestamp設定預設值是default current_timestamp、

timestamp設定隨著表變化而自動更新是on update current_timestamp

1、timestamp default current_timestamp on update current_timestamp

在建立新記錄和修改現有記錄的時候都對這個資料列重新整理

2、timestamp default current_timestamp

在建立新記錄的時候把這個字段設定為當前時間,但以後修改時,不再重新整理它

3、timestamp on update current_timestamp

在建立新記錄的時候把這個字段設定為0,以後修改時重新整理它

mysql timestamp 基本用法

timestamp列型別 timestamp值可以從1970的某時的開始一直到2037年,精度為一秒,其值作為數字顯示。timestamp值顯示尺寸的格式如下表所示 列型別 顯示格式 timestamp 14 yyyymmddhhmmss timestamp 12 yymmddhhmmss time...

MySQL TIMESTAMP相關問題

在mysql中,不僅是插入就算是修改也會更新timestamp的值!在mysql中要記錄建立日期還得使用datetime 然後使用now 函式完成!1,timestamp default current timestamp 在建立新記錄的時候把這個字段設定為當前時間,但以後修改時,不再重新整理它 2...

MySQL timestamp自動更新時間分享

通常表中會有乙個create date 建立日期的字段,其它資料庫均有預設值的選項。mysql也有預設值timestamp,但在mysql中,不僅是插入就算是修改也會更新timestamp的值!這樣一來,就不是建立日期了,當作更新日期來使用比較好!因此在mysql中要記錄建立日期還得使用dateti...