Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to quickly set the automatic add time and update time in the MySQL field

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Let's talk about how to quickly set the automatic add time and update time in the MySQL field. The secret of the text is that it is close to the topic. So, no gossip, let's go straight to the following, I believe you will benefit from reading this article on how to quickly set the automatic add time and update time in the MySQL field.

Description:

The setting time field in the MySQL field automatically adds the creation time and automatic update time settings

Set the field type to: timestamp default is set to current_timestamp ()

The update time field type is: timestamp default value is set to current_timestamp () ON UPDATE current_timestamp ()

SQL syntax and examples create table tb_name (join_time timestamp NULL DEFAULT current_timestamp (), update_time timestamp NULL DEFAULT current_timestamp () ON UPDATE current_timestamp ()) CREATE TABLE mytb (join timestamp NULL DEFAULT current_timestamp (), update timestamp NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (), name varchar (12) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

Data insertion verification

Mysql > insert into mytb (name) value ('xiaoming')

Data update verification

Mysql > update mytb set name= "floret"

Query verification

Is there anything you don't understand about how to quickly set up automatic add time and update time related content in the above MySQL field? Or if you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report