List of standard lengths for database fields

后端 未结 13 1754
日久生厌
日久生厌 2020-12-02 03:30

I\'m designing a database table and once again asking myself the same stupid question: How long should the firstname field be?

Does anyone have a li

相关标签:
13条回答
  • 2020-12-02 03:43

    I would say to err on the high side. Since you'll probably be using varchar, any extra space you allow won't actually use up any extra space unless somebody needs it. I would say for names (first or last), go at least 50 chars, and for email address, make it at least 128. There are some really long email addresses out there.

    Another thing I like to do is go to Lipsum.com and ask it to generate some text. That way you can get a good idea of just what 100 bytes looks like.

    0 讨论(0)
  • 2020-12-02 03:44

    Just looking though my email archives, there are a number of pretty long "first" names (of course what is meant by first is variable by culture). One example is Krishnamurthy - which is 13 letters long. A good guess might be 20 to 25 letters based on this. Email should be much longer since you might have firstname.lastname@somedomain.com. Also, gmail and some other mail programs allow you to use firstname.lastname+sometag@somedomain.com where "sometag" is anything you want to put there so that you can use it to sort incoming emails. I frequently run into web forms that don't allow me to put in my full email address without considering any tags. So, if you need a fixed email field maybe something like 25.25+15@20.3 in characters for a total of 90 characters (if I did my math right!).

    0 讨论(0)
  • 2020-12-02 03:44

    If you need to consider localisation (for those of us outside the US!) and it's possible in your environment, I'd suggest:

    Define data types for each component of the name - NOTE: some cultures have more than two names! Then have a type for the full name,

    Then localisation becomes simple (as far as names are concerned).

    The same applies to addresses, BTW - different formats!

    0 讨论(0)
  • 2020-12-02 03:45

    W3C's recommendation:

    If designing a form or database that will accept names from people with a variety of backgrounds, you should ask yourself whether you really need to have separate fields for given name and family name.

    … Bear in mind that names in some cultures can be quite a lot longer than your own. … Avoid limiting the field size for names in your database. In particular, do not assume that a four-character Japanese name in UTF-8 will fit in four bytes – you are likely to actually need 12.

    https://www.w3.org/International/questions/qa-personal-names

    For database fields, VARCHAR(255) is a safe default choice, unless you can actually come up with a good reason to use something else. For typical web applications, performance won't be a problem. Don't prematurely optimize.

    0 讨论(0)
  • 2020-12-02 03:45

    UK Government Data Standards Catalogue details the UK standards for this kind of thing. It suggests 35 characters for each of Given Name and Family Name, or 70 characters for a single field to hold the Full Name, and 255 characters for an email address. Amongst other things..

    0 讨论(0)
  • 2020-12-02 03:46

    I pretty much always use a power of 2 unless there is a good reason not to, such as a customer facing interface where some other number has special meaning to the customer.

    If you stick to powers of 2 it keeps you within a limited set of common sizes, which itself is a good thing, and it makes it easier to guess the size of unknown objects you may encounter. I see a fair number of other people doing this, and there is something aesthetically pleasing about it. It generally gives me a good feeling when I see this, it means the designer was thinking like an engineer or mathematician. Though I'd probably be concerned if only prime numbers were used. :)

    0 讨论(0)
提交回复
热议问题