1. Examples
CREATE TABLE `job` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`status` varchar(15) DEFAULT NULL COMMENT 'Status 1: In progress 2 Completed 3 Failed',
`create_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`update_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'modify time',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
2. Explanation
During the insert operation, if there is a timestamp field, the property is set to current_ Time stamp, the current system time is inserted regardless of whether the field has a set value
During the update operation, if a timestamp field property is set to ON UPDATE CURRENT_ When the data is updated, this field will automatically update the time
Note: these two properties can be used in combination
Read More:
- [MySQL] mysql 5.5 and 5.6 timestamp default default value CURRENT_TIMESTAMP problem
- MYSQL Create TIMESTAMP and Save Error: ERROR 1067 (42000): Invalid default value for ‘last_updated_on’
- MYSQL Safe Upgraded Error: You are using safe update mode and you tried to update
- Mysql + Mybatis Batch Update Datas Error: BadSqlGrammarException
- [Solved] MySQL Execute update error: error code: 1175
- Mysql Flashback Warning: C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe
- [Solved] ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)
- [Solved] MYSQL Command Execute Error: Can ‘t connect to local MySQL server through socket ‘/tmp/mysql.sock ‘(2) “
- MySql Install Error: Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘
- [Solved]ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
- MYSQL Enter password:ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘
- Error 1406 (22001) in MySQL: data too long for column (Fixed)
- MYSQL Insert Data Error: check the manual that corresponds to your MySQL server version for the right syntax
- How to Solve can‘t connect to local mysql server through socket ‘/var/lib/mysql/mysql.sock‘
- [Solved] Django configures MySQL Error: NameError: name ”_MySQL ‘is not defined
- (Fixed) workbench MySQL Error Code: 2013. Lost connection to MySQL server during query
- How to Fix MySQL error 1005: can’t create table (errno: 150)
- MySQL Install Error: MySQL error 1042: Unable to connect to any of the specified MySQL hosts
- [Solved] CentOS installs MySQL and starts MySQL with error 2002 (HY000)
- MYSQL 5.7 Error Code: 1290. The MySQL server is running with the –secure-file-priv option so it..