MySQL insert not NULL no default error (doesn ' t has a default value)

Source: Internet
Author: User
Tags mysql insert

Today encountered a problem, itself in the local Data execution insert SQL nothing wrong, but on the test environment on the error! Find a long time to find out about MySQL configuration. View Local Database

SELECT @ @sql_mode

is empty, the test environment performs the discovery:

+---------------------+
| @ @sql_mode |
+---------------------+
| Strict_trans_tables |
+---------------------+

This mode is equivalent to adding data to SQL, the syntax of the checksum, if you have set NOT NULL but no default value of the field will be reported

Doesn ' t has a default value of error.

Set sql_mode = ""; it's done.

Therefore, when creating the table, it is best to add some non-mandatory fields with NOT NULL plus the default;

Why do you want to set the field to NOT null?

1, empty value is not space-consuming

2. The null in MySQL is actually occupied space , the following is the explanation from the official MySQL

"NULL columns require additional space in the row to record whether their values is null. For MyISAM tables, each of the NULL column takes one bit extra, rounded up to the nearest byte. "

The conditions for null and NULL queries are not the same, and all the best settings are not null!

This article is from the "7804265" blog, please be sure to keep this source http://7814265.blog.51cto.com/7804265/1789338

MySQL insert not NULL no default error (doesn ' t has a default value)

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.