This article describes how to set the automatic creation time and modification time of MySQL. Share with you for your reference, the details are as follows: The first one is defined by ddl CREATE TABLE `course` ( `course` varchar(255) DEFAULT NULL, `user` varchar(255) DEFAULT NULL, `score` int(11) DEFAULT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time', `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update time', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; The second method is to modify the table design directly through the tool The third method is to modify the fields through SQL statements. -- Modify create_time to set the default time CURRENT_TIMESTAMP ALTER TABLE `course` MODIFY COLUMN `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time'; -- Add update_time and set the default time to CURRENT_TIMESTAMP. Set the update time to ON UPDATE CURRENT_TIMESTAMP. ALTER TABLE `course` ADD COLUMN `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update time'; Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL transaction operation skills", "MySQL stored procedure skills", "MySQL database lock related skills summary" and "MySQL common function summary" I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Vue.js manages the encapsulation of background table components
>>: Specific use of Linux man command
This article shares the specific code for impleme...
need Whether it is a Windows system or a Linux sy...
The simple installation configuration of mysql5.7...
Refer to the official document http://dev.mysql.c...
Table of contents Workaround Why can't I moni...
Table of contents Overview Promise Race Method Re...
When doing a project, it is inevitable to encount...
Definition of Float Sets the element out of the n...
Introduction to MySQL logical architecture Overvi...
Editor: This article discusses the role that inte...
Table of contents 1. Implement the $(".box1&...
Table of contents 1. Switch between production en...
Logpoint-based replication 1. Create a dedicated ...
Demand scenario: The existing PXC environment has...
We often need to summarize data without actually ...