2

[mysql 字段] not null 还是 null default

 1 year ago
source link: https://www.v2ex.com/t/877652
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Java

[mysql 字段] not null 还是 null default

  RedBeanIce · 7 小时 27 分钟前 · 1009 次点击

问题:如图,字段值的设置

今天在看一篇文章,设计数据库的时候所有字段都设置为 not null ,并且给默认值 default null/0 ,我感觉这是不符合实际场景的

我回想我入门的时候也看到过这样子的文章,但是我工作了两三年后发现,我都是根据业务实际来做的,业务允许为空那就是 null ,业务不允许为空我就给 not null ,这个是否必填由产品说了算。

至于 default 属性,是只有选择框,下拉框才需要做的事情。否则都没有 default

==========================隔断线=======

null 还是 not null:根据产品要求来设计

default:根据实际场景,一般只在下拉框等场景使用

如上,请各位指教,我这样应该是对的吧,这类似的文章都是不符合实际的吗?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK