Talking about the problem that MySQL databases contain zero values in China and Japan, mysql zero value

Source: Internet
Author: User

Talking about the problem that MySQL databases contain zero values in China and Japan, mysql zero value

By default, MySQL can insert 0 values into a date. In reality, 0 values in a date are meaningless. You can adjust the SQL _mode variable of MySQL to 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 to 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 a date value containing 0 to 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 discussion about the zero value in the MySQL database in China and Japan is all the content that I have shared with you. I hope to give you a reference and support for the customer's house.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.