程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> 解析MySQL設置當前時間為默認值的方法

解析MySQL設置當前時間為默認值的方法

編輯:關於MYSQL數據庫

MySQL設置當前時間為默認值的問題我們經常會遇到,下面就為您介紹MySQL設置當前時間為默認值的實現全步驟,希望對您能有所啟迪。
數據庫:test_db1
創建表:test_ta1
兩個字段:id              (自增 且為主鍵),
createtime 創建日期(默認值為當前時間)

方法一、是用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 屬性選擇<INSERT-TimeStamp>
以上就是MySQL設置當前時間為默認值的方法介紹。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved