Parsing Mysql Sets the current time as the default value method _mysql

Source: Internet
Author: User
Tags current time

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.