场地大小推荐?
有没有什么地方可以找到有关应在数据库中设置的字段长度的建议?
我刚刚开始修复一个项目中的一些错误,几乎所有字段都设置为 50...
名字、姓氏、电子邮件...
我认为在这种情况下,名字和姓氏可能小于 50.. 无论如何,
问一下也没什么坏处=)
Is there any place where I can find recommendation about the length of the fields that I should set in a database?
I just started fixing some bugs in a project that almost all of its fields are set to 50...
first name, last name, email...
I think in this case, first name and last name could be less than 50...
anyway, doesn't hurt to ask =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正确答案是“尽可能大”。
大多数数据库字段实际上都是可变大小的,因此您选择什么随机数并不重要。
因此,选择你能得到的最大随机数。
除非有令人信服的理由不这样做,否则我会选择 255。
缩短的一个令人信服的原因是整体行大小太大。
另一个令人信服的原因是最大长度的实际定义标准。
The correct answer is "as large as possible".
Most database fields are actually variable size, so it doesn't matter what random number you pick.
Therefore, pick the largest random number you can get away with.
I go with 255 unless there's a compelling reason not to.
One compelling reasons for shorter is the overall row size is too huge.
The other compelling reason is an actual defined standard for maximum length.
如果相关列用于存储包含规范的内容(例如电子邮件地址),则使用该规范。例如,电子邮件地址的最大允许长度为 256 个字符。
@
符号之前的任何内容都不能超过 64 个字符。具有已知规格的代码的其他示例包括银行代码、货币代码、语言代码、VIN、ISBN 等。您应该使用最适合该值的长度。目标是通过将列的规范与数据的规范相匹配,使数据库尽可能地保护自己免受不良数据的影响。然而,名字就比较棘手了。名字和姓氏的概念本身并不通用。此外,政府机构之间名字和姓氏的长度也有很大差异。我对名字和姓氏的倾向是从 25 个字符开始,看看是否足够(25 个字符的名字或姓氏是一个非常长的名字)。但是,请注意您可能会遇到国际名称的麻烦。因此,最好创建一个通用的“姓名”列,用户可以在其中输入该人的全名。
就包含所有这些规范的网站而言,据我所知,还没有这样的地方。 Google 是您的最佳选择或权威来源(例如,IRS 提供税务标识符、DMV 提供驾驶执照规范、USPS 提供地址规范等)
RFC3696
If the column in question is used to store something that contains a specification, like email address, then use that specification. For example, the maximum allowable length for an email address is 256 characters. Anything prior to the
@
sign can be no longer than 64 characters. Other examples of codes that have known specifications are bank codes, currency codes, language codes, VINs, ISBNs etc. You should use the length most appropriate to the value. The objective is to have the database protect itself against bad data as much as possible by matching the specification of the column to the specifications of the data.Names, however, are trickier. The very concept of a first name and last name is not universal. In addition, the length of first and last names varies quite a bit between government agencies. My inclination with first and last name is to start with 25 characters and see if that will suffice (25 character first or last name is a seriously long name). However, be aware you may run into trouble with international names. Thus, it also best to create a general "Name" column where users can enter the person's full name.
In terms of a site that contains all of these specifications, there is no such place as far as I'm aware. Google is your best choice or the authoritative source (e.g. IRS for tax identifiers, DMV for driver's license specs, USPS for address specs etc.)
RFC3696
我通常使用 32 来表示名字/姓氏等内容。我有一个姓氏很大的朋友,他说服我允许输入这么长时间。
I normally use 32 for things like first name/last name. I have a friend with a hefty surname which convinced me to allow for input that long..
25 通常是一个安全的选择。如果您将来需要修改,只需几行代码即可......
25 is usually a safe-bet. If you need to modify in the future this is possible with just a few lines of code...