Home > Database > navicat > body text

How to set default value for datetime in navicat

angryTom
Release: 2019-08-10 15:47:37
Original
10254 people have browsed it

How to set default value for datetime in navicat

When using navicat to design the fields of the table, you can set default values ​​for the fields. However, fields of datetime type cannot be set. Let’s explain this problem in detail for everyone.

Recommended tutorial: MySQL database introductory tutorial

##Because the default value of MySQL's current field does not support functions , so it is impossible to set the default value in the form of create_time datetime default now(). An alternative is to use the TIMESTAMP type instead of the DATETIME type.

The TIMESTAMP column type automatically tags INSERT or UPDATE operations with the current date and time. If there are multiple TIMESTAMP columns, only the first one is updated automatically.

Automatically updating 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. Column values ​​are not explicitly specified in an UPDATE statement and some other columns change values. (Note that an UPDATE setting a column to a value it already has will not cause the TIMESTAMP column to be updated, because if you set a column to its current value, MySQL ignores the change for efficiency.)

3 .You explicitly set the TIMESTAMP column to NULL.

4. TIMESTAMP columns other than the first one can also be set to the current date and time by setting the column to NULL, or NOW().

Therefore, select the date type as TimestAmp to allow empty emptiness

CREATE TABLE test ( uname varchar(50) NOT NULL,updatetime timestamp NULL DEFAULTCURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Copy after login

If you want to operate under navicat, set the field to TimestAmp, and then write the Current_timestStamp just

The above is the detailed content of How to set default value for datetime in navicat. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template