Default Value for Datetime Datatype: NOW() or '0000-00-00 00:00:00'?
To set the default value for datetime datatype, you can consider the following options:
Current Default Value: '0000-00-00 00:00:00'
ALTER TABLE users MODIFY lastVisitDate datetime DEFAULT '0000-00-00 00:00:00';
Dynamic Default Value: NOW()
CREATE TABLE users ( registerDate datetime DEFAULT CURRENT_TIMESTAMP );
ALTER TABLE users MODIFY registerDate datetime DEFAULT CURRENT_TIMESTAMP;
Note: Prior to MySQL 5.6.5, dynamic default values for datetime were not supported. You could use the TIMESTAMP datatype instead, but it only allowed one auto-updated timestamp column per table.
The above is the detailed content of DATETIME Default Value: NOW() or '0000-00-00 00:00:00'?. For more information, please follow other related articles on the PHP Chinese website!