MySQL set the current time is the default value of the problem we often encounter, below to introduce you to the MySQL set the current time for the default value of the implementation of the full steps, I hope you can be enlightened.
Database: TEST_DB1
CREATE TABLE: Test_ta1
Two fields: ID (self-increasing and primary key),
Createtime Date Created (default is current time)
Method one, using the Alert table statement:
Copy Code code as follows:
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 ();
method Two, direct creation convenience:
Copy Code code as follows:
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;
Method III, visualization tools such as Mysql-front
Right-click the Createtime property
Change the type attribute value to timestamp
Default Property Selection <INSERT-TimeStamp>
This is the MySQL set the current time is the default value of the method introduction.