In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the use of CURRENT_TIMESTAMP in MySQL". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the use of CURRENT_TIMESTAMP in MySQL".
The use of CURRENT_TIMESTAMP
As we all know, the date type of MySQL can use CURRENT_TIMESTAMP to specify the default value, but this depends on the version of MySQL and the specific type of date. Only versions after 5.6 can use CURRENT_TIMESTAMP as the default value for DATETIME.
For example:
ALTER TABLE t_user ADD update_time DATETIME DEFAULT CURRENT_TIMESTAMP
In versions prior to 5.6, the following error occurred when using CURRENT_TIMESTAMP as the default value
[Err] 1067-Invalid default value for 'update_time'
Prior to MySQL version 5.6.5, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP was only available for TIMESTAMP, and at most one TIMESTAMP field in a table was allowed to use this feature. Starting from MySQL 5.6.5, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP is available for both TIMESTAMP and DATETIME, and there is no limit to the number.
Timestamp uses CURRENT_TIMESTAMP to report errors
The following error occurred in the project:
Error updating database.
Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'createTime' cannot be null
The data model is as follows:
/ * creation time cannot be empty * / createTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time', / * update time cannot be empty * / updateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'update time'
After a series of troubleshooting, it is located that it is due to the problem of the global variable "explicit_defaults_for_timestamp" of different versions of the MySQL database.
-- View explicit_defaults_for_timestamp default value SHOW GLOBAL VARIABLES LIKE "explicit_defaults_for_timestamp";-- modify explicit_defaults_for_timestamp default value SET @ @ global.explicit_defaults_for_timestamp=OFF
If the parameter value is "ON":
Thank you for your reading, the above is the content of "what is the use of CURRENT_TIMESTAMP in MySQL". After the study of this article, I believe you have a deeper understanding of the use of CURRENT_TIMESTAMP in MySQL, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.