Home  >  Article  >  Database  >  What does null mean in mysql

What does null mean in mysql

青灯夜游
青灯夜游Original
2020-09-30 11:56:509028browse

In mysql, null represents nothing. It is an undefined value that takes up space, but cannot participate in any calculations, because a null value will be empty if it participates in any calculation. Null makes indexes, index statistics, and values ​​more complex and affects the optimizer's judgment.

What does null mean in mysql

null in mysql is really difficult to deal with, and many experts are often tricked by it during sql optimization

  • In MySQL, null is unknown and takes up space. Null makes indexes, index statistics, and values ​​more complex and affects the optimizer's judgment.

  • Null value ('') does not occupy space. Note that there is no space between the '' of the null value.

  • When count() counts the number of records in a column, if a NULL value is used, it will be automatically ignored by the system, but the null value will be counted.

  • Use is null or is not null to judge null, but use ='' or <>'' to judge null characters.

  • For the timestamp data type, if a NULL value is inserted, the value that appears is the current system time. If you insert a null value, '0000-00-00 00:00:00' will appear.

  • For already created tables, the performance improvement brought by changing ordinary columns from null to not null is relatively small, so there is no need to search one by one and modify not from null when tuning. null.

  • For already created tables, if you plan to create an index on a column, try to change it to not null, and use 0 or a special value or a null value''.

In short, for tables, usually all are specified as not null, and default '' or other default values ​​are specified. The advantages outweigh the disadvantages.

Recommended tutorial: mysql video tutorial

The above is the detailed content of What does null mean in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn