Mysql default value does not support functions and set the default time _ MySQL
Source: Internet
Author: User
Default mysql does not support functions and sets the default time bitsCN.com.
The default value of mysql does not support functions and the default time is set. Java code 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 create_time datetime default now.
The alternative is to use the TIMESTAMP type instead of the DATETIME type. The TIMESTAMP column type automatically marks the INSERT or UPDATE operation with the current date and time. If multiple TIMESTAMP columns exist, only the first one is automatically updated. Automatic update of the first TIMESTAMP column occurs under any of the following conditions: 1. the column value is not explicitly specified in an INSERT or load data infile statement.
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 .) 3. you explicitly set the TIMESTAMP column as NULL. 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 (). In addition, you can also use trigger to implement this function in versions later than 5.0. 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; in Java code mysql, how do I set the default time to the current time? Set the date type to timestamp. you can create table 'dtal' ('uname' varchar (50) not null, 'udate' timestamp null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP) ENGINE = InnoDB default charset = utf8; if you want to operate under navicat, set the field to timestamp, and enter CURRENT_TIMESTAMP as the DEFAULT value.
BitsCN.com
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.