Analyzing the MySql CURRENT_TIMESTAMP function by example

Analyzing the MySql CURRENT_TIMESTAMP function by example

When creating a time field

DEFAULT CURRENT_TIMESTAMP

Indicates that when inserting data, the default value of this field is the current time

ON UPDATE CURRENT_TIMESTAMP

Indicates that every time this data is updated, the field will be updated to the current time

These two operations are maintained by the MySQL database itself, so the two fields [Creation Time] and [Update Time] can be generated based on this feature, and no code is required to maintain them.

as follows:

CREATE TABLE `mytest` (
  `text` varchar(255) DEFAULT ''COMMENT 'content',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update time'
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

Can be operated directly through navicat's visual interface

So how do you set a specific default time?

As follows, note that there are two single quotes

TIMESTAMPDEFAULT 'yyyy-mm-dd hh:mm:ss'

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to MySQL error TIMESTAMP column with CURRENT_TIMESTAMP
  • Detailed explanation of TIMESTAMP usage in MySQL
  • Share the pitfalls of MySQL's current_timestamp and their solutions

<<:  How to use sed command to efficiently delete specific lines of a file

>>:  Webpack builds scaffolding to package TypeScript code

Recommend

How to configure pseudo-static and client-adaptive Nginx

The backend uses the thinkphp3.2.3 framework. If ...

Solution to MySQL error code 1862 your password has expired

The blogger hasn't used MySQL for a month or ...

Docker network mode and configuration method

1. Docker Network Mode When docker run creates a ...

Detailed analysis of mysql MDL metadata lock

Preface: When you execute a SQL statement in MySQ...

Differences in the hr separator between browsers

When making a web page, you sometimes use a dividi...

Analyze Tomcat architecture principles to architecture design

Table of contents 1. Learning Objectives 1.1. Mas...

Detailed explanation of nginx reverse proxy webSocket configuration

Recently, I used the webSocket protocol when work...

JavaScript Objects (details)

Table of contents JavaScript Objects 1. Definitio...

Detailed tutorial on uploading and configuring jdk and tomcat on linux

Preparation 1. Start the virtual machine 2. git t...

4 principles for clean and beautiful web design

This article will discuss these 4 principles as t...

How to install and configure ftp server in CentOS8.0

After the release of CentOS8.0-1905, we tried to ...

How to sort a row or column in mysql

method: By desc: Neither can be achieved: Method ...

Detailed explanation of the marquee attribute in HTML

This tag is not part of HTML3.2 and is only suppo...

Use Smart CSS to apply styles based on the user's scroll position

By adding the current scroll offset to the attrib...