MySQL is recommended as far as NOT NULL column properties

Unless you have a very special reason to use a NULL value, you should always keep your field holds NOT NULL. It looks like a little controversy, please read on.

First, we have to figure out the concept of "null" and "NULL" is:
1, the value is not empty space of
2, MySQL NULL in fact footprint

The so-called NULL is nothing, not even \ 0 are not, \ 0 character in the string is the end, but in the space of physical memory is equal to one byte, but even this is a NULL byte at all. In the database is strictly distinguish between any number of operations are carried out with NULL NULL, to determine whether the value is equal to NULL, can not simply use =, but rather use the IS NULL keyword.

 

Database ID field set to NOT NULL, only indicating that the field can not be NULL, that is to say only in the
INSERT INTO table (ID) VALUES ( NULL);
in this case the database will be given, and
INSERT INTO table (ID) VALUES ( ');
this description is not NULL, the database will be populated based on the default values set ID, or if it is automatically self-energizing field plus one equals a default operation.


Try to avoid NULL: to be designated as NOT NULL, unless you want to store NULL. In MySQL, the column contains a null value is difficult to query optimization, but also does not store NULL values ​​of the index table, so if the index field can be NULL, the efficiency of the index will drop a lot. As they enable the index, the index statistics, and comparison operations more complex. You should use 0, or a special value NULL value instead of an empty string.

Published 393 original articles · won praise 41 · views 260 000 +

Guess you like

Origin blog.csdn.net/qq_32440951/article/details/88321799