MySQL Sets the default time value _mysql

Source: Internet
Author: User
Tags datetime
So to
Copy Code code as follows:

Create_time datetime default Now ()

It is not possible to set the default value in the form.
The alternative is to use the timestamp type instead of the datetime type.
Current_timestamp: When I update this record, this field in this record will not change.
Current_timestamp on update current_timestamp: When I update this record, this field in this record will change. That time becomes the time of the update. (Note that an update setting lists the values it already has, which will not cause the timestamp column to be updated because if you set a list of its current values, MySQL ignores the changes for efficiency.) If there are multiple timestamp columns, only the first automatic update is available.
The timestamp column type automatically marks the INSERT or update operation with the current date and time.
If there are multiple timestamp columns, only the first automatic update is available.
Automatic Updates the first timestamp column occurs under any of the following conditions:
The column value is not explicitly specified in an INSERT or load DATA infile statement.
The column value is not explicitly specified in an UPDATE statement and some other columns change the value. (Note that an update setting lists the values it already has, which will not cause the timestamp column to be updated because if you set a list of its current values, MySQL ignores the changes for efficiency.) )
You explicitly set the timestamp column to null.
Timestamp columns other than the first can be set to the current date and time, as long as the column is set to null or now ().
Trigger can also be used to implement this functionality in more than 5.0 versions.
Copy Code code as follows:

CREATE TABLE Test_time (
ID Int (11),
Create_time datetime
);
Delimiter |
Create trigger Default_datetime before insert on Test_time
For each row
If new.create_time is null then
Set new.create_time = Now ();
End if;|
delimiter;

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.