MySQL table structure uses timestamp to automatically get the current time

Source: Internet
Author: User
Tags command line current time datetime table definition phpmyadmin

One, Miss Access era

The table structure of access if you want to automatically insert the current time, you can enter the default value now () when the column is defined and you can automatically insert the current time. and MySQL does not work, MySQL this dongdong default is the product below the command line, if not later have phpmyadmin this graphical interface dongdong words, estimated generally people are depressed. Of course, later MySQL official also out of the corresponding GUI tools, of course, exe. By MySQL This network service program's many users are renting the virtual host premise, looks like this kind of dongdong is also a luxury. HoHo, again digress, today's topic is using the timestamp type in MySQL.

Second, their own hands, ample clothing.

Used to be the type of datetime, but it seems that way, can not let MySQL automatically get the current time, but must go through php date ("y-m-d h:i:s"), and then update the past. Seems to be in the use of phpMyAdmin Insert test data When I'm sorry I lazy people. Later after the expert advice, did the following changes, the table column of datetime type changed to the TIMESTAMP type, and his default value changed to Current_timestamp, you can achieve my purpose.

But this dongdong has a small limit, is a table can only have one datestamp column set as the default Current_timestamp, the second can not set the default success, will return the following:

#1293-incorrect table definition; There can be only one TIMESTAMP column with Current_timestamp in DEFAULT or on UPDATE clause

。 This seems a bit uncomfortable to say. hoho~

Three, send 2 charts, give a contrast effect.

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.