null 有害吗?
今天我回避了一场关于数据库中空值的激烈争论。
我的观点是 null 是未指定值的一个很好的指示符。 团队中的其他人都有自己的观点,认为零和空字符串是正确的选择。
是他们懒还是我太严格?
I dodged a heated debate concerning nulls in the database today.
My opinion is that null is an excellent indicator of unspecified values. Everyone else in the team, that has an opinion, thinks zero and empty strings are the way to go.
Are they lazy or am I too strict?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
他们很懒,不理解数据库中 null 的基本概念。 空值很有用并且有其用途。 既不应避免也不应不当使用它们。
They are lazy and do not understand the basic idea of a null in the database. Nulls are useful and have a purpose. They should neither be avoided nor used inappropriately.
null 表示没有值,而 0 则不然,如果你看到 0,你不知道含义,如果你看到 null,你就知道它是一个缺失值
我认为 null 更清晰,0 和 '' 很混乱,因为它们没有清楚地表明存储值的意图
null means no value while 0 doesn't, if you see a 0 you don't know the meaning, if you see a null you know it is a missing value
I think nulls are much clearer, 0 and '' are confusing since they don't clearly show the intent of the value stored
当然,如果未指定,那么 null 是一个很好的指示符,零意味着某些东西,而 null 则不然。 虽然我不是专家 DB..
Surely if its unspecified then null is a good indicator, zero means something whereas null doesnt. I'm no expert DB though..
尽管使用 null 需要额外的工作,但我认为非指定字段和设置为空或 0 的字段之间应该存在差异。
您还能说用户故意设置值 0 或者如果他没有设置值没有设置字段?
Despite the extra work that using nulls requires I think there SHOULD be a difference between a non specified field and a field set to empty or 0.
Who else will you be able to say that a user set the value 0 on purpose or if he didn't set the field?