《MYSQL教程解析MySQL設置當前時間為默認值的方法》要點:
本文介紹了MYSQL教程解析MySQL設置當前時間為默認值的方法,希望對您有用。如果有疑問,可以聯系我們。
MySQL設置當前時間為默認值的問題我們經常會遇到,下面就為您介紹MySQL設置當前時間為默認值的實現全步驟,希望對您能有所啟迪.
數據庫:test_db1
創建表:test_ta1
兩個字段:id????????????? (自增 且為主鍵),
createtime 創建日期(默認值為當前時間)MYSQL學習
方法一、是用alert table語句:
MYSQL學習
代碼如下:
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 屬性選擇<INSERT-TimeStamp>
以上就是MySQL設置當前時間為默認值的方法介紹.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/5511.html