Mysql-default settings

Source: Internet
Author: User

Both statements Insert a value into the phone column, but the first inserts a NULL value and the second inserts an empty s Tring. The meaning of the first can be regarded as "phone number are not known" and the meaning of the second can regarded as " The person was known to has no phone, and thus no phone number. "
MySQL:: MySQL 8.0 Reference Manual:: b.5.4.3 problems with NULL Values

Null: Unknown, value not set
Empty string ("): null, set but null value

For MyISAM tables, NULL columns require additional space in the row to record whether their values is NULL. Each of the NULL column takes one bit extra, rounded up to the nearest byte.
MySQL:: MySQL 5.7 Reference Manual:: c.10.4 Limits on Table Column Count and Row Size

I see a lot of blog on the Internet is written in the MyISAM null accounted for one, empty string (") one does not occupy, I feel a bit of a problem (should be set to NULL when creating the table field will be more than one to save null) but use Information_ The Data_length field test for the tables table of the schema database found that the increment of either inserting null or empty string (') is the same:

PS: Using the select length(‘‘), length(null) query result is really a ' length of 0

mysql> select length(‘‘), length(null);+------------+--------------+| length(‘‘) | length(null) |+------------+--------------+|          0 |         NULL |+------------+--------------+
Conclusion:

Because the processing of NULL is laborious, and when Null is said to not walk the index, in addition to special cases or empty string ("") convenient point (as if there is nothing to do with it).

Mysql-default settings

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.