MySQL date default system time MySQL Default Value does not support functions

Source: Internet
Author: User

Because the default value of the current MySQL field does not support functions, it is impossible to set the default value in the form of <br/> create_time datetime default now () <br/>. <Br/> the alternative solution is to use the timestamp type instead of the datetime type. <Br/> the timestamp column type Automatically marks the insert or update operation with the current date and time. <Br/> if multiple timestamp columns exist, only the first one is automatically updated. <Br/> the first timestamp column is automatically updated under any of the following conditions: <br/> 1. The column value is not explicitly specified in an insert or load data infile statement. <Br/> 2. The column value is not explicitly specified in an update statement and other columns change the value. (Note that setting an Update column as its existing value does not cause the timestamp column to be updated, because if you set a column as its current value, MySQL ignores the changes for efficiency .) <Br/> 3. you explicitly set the timestamp column as null. <br/> 4. the timestamp column except the first one can also be set to the current date and time, as long as the column is set to null, or now (). <Br/> you can also use trigger to implement this function in analyticdb 5.0 or a later version. <Br/> Create Table test_time (<br/> ID int (11), <br/> create_time datetime <br/> ); <br/> delimiter | <br/> Create trigger default_datetime before insert on test_time <br/> for each row <br/> if new. create_time is null then <br/> set new. create_time = now (); <br/> end if; | <br/> delimiter;

 

In MySQL, how does one set the default time to the current time? </P> <p> you can set the date type to timestamp. <br/> Create Table 'dtal' (<br/> 'uname' varchar (50) not null, <br/> 'udate' timestamp null default current_timestamp on update current_timestamp <br/>) engine = InnoDB default charset = utf8; <br/> to operate under navicat, set the field to timestamp, and enter current_timestamp by default.

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.