The following editor will bring you a brief discussion on the problem of zero values contained in dates in MySQL database. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look
By default, MySQL can accept inserting 0 values into dates. In reality, 0 values in dates have little meaning. Adjusting MySQL's sql_mode variable can achieve the goal.
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'; set @@session.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION';
Example:
There is a table for logging
create table app_logs( id int not null auto_increment primary key, log_tm timestamp not null, log_info varchar(64) not null) engine=innodb,charset=utf8;
Insert interesting date values into the log table
insert into app_logs(log_tm,log_info) values(now(),'log_info_1'); insert into app_logs(log_tm,log_info) values('2016-12-01','log_info_2');
Insert date values including 0 into the log table
insert into app_logs(log_tm,log_info) values('2016-12-00','log_info_2'); ERROR 1292 (22007): Incorrect datetime value: '2016-12-00' for column 'log_tm' at row 1
The above is the detailed content of A brief introduction to the problem of zero values in dates in MySQL databases. For more information, please follow other related articles on the PHP Chinese website!