List of standard lengths for database fields

后端 未结 13 1781
日久生厌
日久生厌 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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.

提交回复
热议问题