MySQL設定當前時間為預設值的方法

2023-01-29 00:46:23 字數 851 閱讀 6727

方法

一、是用alert table語句:

複製****如下:

use test_db1; 

create table test_ta1( 

id mediumint(8) unsigned not nulll auto_increment, 

createtime datetime, 

primary key (id) 

)engine=innodb default charset=gbk; 

alert table test_ta1 change createtime createtime timestamp not null default now(); 

方法

二、直接建立方便:

複製****如下:

use test_db1; 

create table test_ta1( 

id mediumint(8) unsigned not nulll auto_increment, 

createtime timestamp not null default current_timestamp, 

primary key (id) 

)engine=innodb default charset=gbk; 

方法

三、視覺化工具如 mysql-front

右擊createtime屬性

把type屬性值改為timestamp

default 屬性選擇

以上就是mysql設定當前時間為預設值的方法介紹。

MySQL設定當前時間為預設值的方法

在mysql建立表的時候經常會遇到建立日期欄位需要設定當前時間為預設值的問題,下文就教您一個處理該問題的放法,供您參考借鑑。ad mysql設定當前時間為預設值的問題我們經常會遇到,下面就為您介紹mysql設定當前時間為預設值的實現全步驟,希望對您能有所啟迪。資料庫 test db1 建立表 tes...

MySQL設定當前時間為預設值的方法

mysql設定當前時間為預設值的問題我們經常會遇到,下面就為您介紹mysql設定當前時間為預設值的實現全步驟,希望對您能有所啟迪。資料庫 test db1 建立表 test ta1 兩個欄位 id 自增 且為主鍵 createtime 建立日期 預設值為當前時間 方法一 是用alert table語...

Mysql中設定預設時間為當前值

1 直接在建立表時新增該列並宣告預設值,如下 create table table1 id int 11 not null,createtime timestamp null default current timestamp engine innodb default charset utf8 若...