Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

数据库设计( scheme 设计 ), 应该极力避免 NULL 吗?

实际现象

了解到:

  1. NULL 语义不清晰

  2. query 时不好优化

  3. 如果表示空值, 可以有其他的替代方式( 逻辑上 )

    • VARCHAR(100) NOT NULL DEFAULT '';

    • INT NOT NULL DEFAULT 0;

预期现象

  1. 希望能了解在设计scheme的时候, 对待NULL的态度( 记得有看过一篇文章说过, 应该尽量: NOT NULL DEFAULT XXX)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

是,应该尽可能避免可为NULL的列,且尽可能显示设置默认值,尤其是被索引的列。mysql中,null占空间,如果该值被索引,那么其索引无效。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...