mysql - Database design (scheme design), should NULL be avoided as much as possible?
仅有的幸福
仅有的幸福 2017-05-18 10:54:25
0
2
729

Actual Phenomenon

Learned:

  1. NULL semantics are unclear

  2. Query is not easy to optimize

  3. If it represents a null value, there can be other alternatives (logically)

    • VARCHAR(100) NOT NULL DEFAULT '';

    • INT NOT NULL DEFAULT 0;

Expected Phenomenon

  1. I hope to understand the attitude towards NULL when designing a scheme (I remember reading an article saying that you should try: NOT NULL DEFAULT XXX)

仅有的幸福
仅有的幸福

reply all(2)
巴扎黑

Yes, NULL columns should be avoided as much as possible, and default values ​​should be explicitly set as much as possible, especially for indexed columns. In mysql, null takes up space. If the value is indexed, its index is invalid.

某草草

Yes, when judging that a field is not empty, you also need to use is not null. NULL in mysql actually takes up space. NULL values ​​will not be stored in B-tree indexes, so if the indexed field can be NULL, the index The efficiency will drop a lot.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template