MySQL建立資料表TIMESTAMP型別字段問題

2021-08-28 13:30:18 字數 721 閱讀 9399

今天在匯入資料時出現了這個錯誤:

incorrect table definition; there can be only one timestamp column with current_timestamp in default or on update clause
意思時一張表中不能同時又兩個預設當前時間的timestamp 字段。

1、把第乙個設定為current_timestamp而第二個沒有設定預設值

2.、資料庫版本問題 mysql5.6 之前的版本是不可以這樣設定的。如果可以的話請更換資料庫版本

3、使用觸發器解決。

我的時第一種解決方式。例如如下:

create table test

( id int(10) unsigned primary key not null,

updatedat timestamp default current_timestamp on update current_timestamp,

createdat timestamp

);

就可以在一張表中設定多個timestamp欄位。

因為current_timestamp在對錶資料進行修改時,重新整理為當前時間,在乙個表中如果多列為current_timestamp,那麼這些列的資料都是一樣的,這樣毫無意義,並且耗費資源。

建立mysql資料表

mysql建表語句 create table if not exists db name.table name colunum1 date not null comment 列欄位說明 colunum2 int 11 not null comment 列欄位說明 colunum3 int 11 no...

MYSQL 建立資料表

rdbms即關聯式資料庫管理系統 relational database management system 的特點 rdbms術語 資料庫 一些關聯的表的集合 資料表 資料的矩陣。等同於簡單的電子 列 同一類資料 行 一組相關資料,稱為乙個記錄 冗餘 儲存量被資料,使系統速度更快。主鍵 唯一。外來...

MySQL 建立資料表

建立mysql資料表需要以下資訊 以下為建立mysql資料表的sql通用語法 create table table name column name column type 以下例子將在 runoob 資料庫中建立資料表runoob tbl runoob tbl runoob id int not ...