数据库表是否具有默认值?

编程入门 行业动态 更新时间:2024-10-26 04:20:47
本文介绍了数据库表是否具有默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在与开发人员讨论一个表使用默认值的问题。

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 ;)

更多推荐

数据库表是否具有默认值?

本文发布于:2023-10-18 12:21:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:默认值   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!