MySQL設(shè)置當(dāng)前時(shí)間為默認(rèn)值的方法
MySQL設(shè)置當(dāng)前時(shí)間為默認(rèn)值的問(wèn)題我們經(jīng)常會(huì)遇到,下面就為您介紹MySQL設(shè)置當(dāng)前時(shí)間為默認(rèn)值的實(shí)現(xiàn)全步驟,希望對(duì)您能有所啟迪。
數(shù)據(jù)庫(kù):test_db1
創(chuàng)建表:test_ta1
兩個(gè)字段:id (自增 且為主鍵),
createtime 創(chuàng)建日期(默認(rèn)值為當(dāng)前時(shí)間)
方法一、是用alert table語(yǔ)句:
- 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)建方便:
- 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)前時(shí)間為默認(rèn)值的方法介紹。
【編輯推薦】