解析MySQL設(shè)置當(dāng)前時間為默認(rèn)值的方法
更新時間:2013年06月14日 11:15:48 作者:
本篇文章是對MySQL設(shè)置當(dāng)前時間為默認(rèn)值的方法進行了詳細的分析介紹,需要的朋友參考下
MySQL設(shè)置當(dāng)前時間為默認(rèn)值的問題我們經(jīng)常會遇到,下面就為您介紹MySQL設(shè)置當(dāng)前時間為默認(rèn)值的實現(xiàn)全步驟,希望對您能有所啟迪。
數(shù)據(jù)庫:test_db1
創(chuàng)建表:test_ta1
兩個字段:id (自增 且為主鍵),
createtime 創(chuàng)建日期(默認(rèn)值為當(dāng)前時間)
方法一、是用alert table語句:
復(fù)制代碼 代碼如下:
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();
方法二、直接創(chuàng)建方便:
復(fù)制代碼 代碼如下:
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 屬性選擇<INSERT-TimeStamp>
以上就是MySQL設(shè)置當(dāng)前時間為默認(rèn)值的方法介紹。
相關(guān)文章
mysql 5.7.17 安裝配置方法圖文教程(windows)
這篇文章主要為大家分享了mysql 5.7.17 安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01MySQL 5.7 學(xué)習(xí)心得之安全相關(guān)特性
這篇文章主要介紹了MySQL 5.7 學(xué)習(xí)心得之安全相關(guān)特性 的相關(guān)資料,需要的朋友可以參考下2016-07-07