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
1. A container is an independently running applic...
As shown below: //Query the year and month of the...
This article shares the specific code of JavaScri...
Table of contents Introduction Example: Event del...
1. Background 1. Briefly introduce the shared sto...
Table of contents 1. Definition and Use 1.1 Defin...
Introduction: The disadvantages of storing all da...
Original data and target data Implement SQL state...
MYSQL officially provides an Installer method to ...
This article example shares the specific code of ...
Sample code: import java.util.Random; import java...
Table of contents getting Started Data storage Co...
Table of contents for loop While Loop do-while lo...
Simple function: Click the plug-in icon in the up...
Today I want to summarize several very useful HTML...