开发者

Field size recommendation?

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 开发者_如何学Cthat 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 =)


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.


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


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 is usually a safe-bet. If you need to modify in the future this is possible with just a few lines of code...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜