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 manually install MySQL 5.7 on CentOS 7.4

MySQL database is widely used, especially for JAV...

MySQL triggers: creating multiple triggers operation example analysis

This article uses an example to describe the crea...

Detailed explanation of the basic knowledge of front-end componentization

Table of contents Basic concepts of components Th...

Serial and parallel operations in JavaScript

Table of contents 1. Introduction 2. es5 method 3...

Docker beginners' first exploration of common commands practice records

Before officially using Docker, let's first f...

How to use CSS media query aspect-ratio less

CSS media query has a very convenient aspect rati...

XHTML Web Page Tutorial

<br />This article is mainly to let beginner...

Detailed explanation of routes configuration of Vue-Router

Table of contents introduce Object attributes in ...

Solve nginx "504 Gateway Time-out" error

Students who make websites often find that some n...

Web Design Tutorial (7): Improving Web Design Efficiency

<br />Previous article: Web Design Tutorial ...

How to change $ to # in Linux

In this system, the # sign represents the root us...

Web design reference firefox default style

Although W3C has established some standards for HT...

A few things about favicon.ico (it’s best to put it in the root directory)

Open any web page: for example, http://www.baidu....

How to access the local machine (host machine) in Docker

Question How to access the local database in Dock...