我正在与开发人员讨论一个表使用默认值的问题。
I was having a discussion with a developer at work on the issue of should a table use default values. Is there a hard and fast rule on this or is it a gray area in best practices?
推荐答案我的规则:如果有很多记录将使用该默认值(至少在最初),然后我喜欢使用它作为默认值。例如,在线商店中的产品的图像表可以具有 images / NoPictureYet.png 的默认路径。最终,这些将被替换,但对于批量加载的数据,其中图片根本不存在(也许大多数他们永远不会!),默认是有意义的(至少对我来说)。
My rule: if many records will use that default (at least initially) then I like to use it as a default. For example, an image table for products in an online store might have a default path of images/NoPictureYet.png. Eventually, those will get replaced, but for batch loads of data where the pictures simply don't exist yet (and maybe most of them never will!), a default makes sense (to me, at least).
如果没有合理的默认值(例如客户数据库中的名字 - 我不希望MY名称默认为FirstName),那么我使它不可为空,没有默认 - 这是应用程序的责任,以确保输入正确的值。
If there is no sensible default (such as "first name" in a customer database - I don't want MY name defaulted to "FirstName"), then I make it non-nullable and no default - it's the application's responsibility to ensure that a correct value gets entered.
但没有严格和快速的规则。这一切都有所不同);
But no hard and fast rules on this. It all varies a little ;)
更多推荐
数据库表是否具有默认值?
发布评论