开发者

What should be the typical length of user's Full Name in database [duplicate]

开发者 https://www.devze.com 2023-01-27 20:49 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: List of standard lengths for database fields
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

List of standard lengths for database fields

Simple as that, what should be the typical length of allowed "Full Name" of a user in 开发者_JS百科database?

When I create users table, I usually set it as varchar 31 or 32 (according to performance). What do you guys use and what's standard/typical convention.


Sidenote: I never face problem in email length (as I set it 254) and password (hash, 32 length).


The maximum your average varchar field allows (254?).

You are not winning anything by making it arbitrarily shorter. The fine-grained size controls on numbers and chars are more or less a relic from the past, when every byte mattered. It can matter today - if you are dealing with tens or hundreds of millions of rows, or thousands of queries per sec. For your average database (i.e. 99% of them) performance comes from proper indexing and querying, NOT making your rows a couple of bytes smaller.

Only restrict the length of a field when there is some formal specification that defines a maximum length, like 13 digits for an EAN code or 12 characters for an ISIN.


Full name is always a computed column composed of first, middle, last, prefix, suffix, degree, family name, etc in my designs. The list of individual columns are determined by the targeted local of the app. The display length of 'Full Name' is normall contained within the app design not the database. There is not any space savings in SQL Server between varchar(32) and varchar(256). Varchar(256) is my choice.

I never want to be in the meeting when someone says "Your db design will not hold all our data".

You are always assigning an ID to the user so you can join and do look-ups using the ID instead of the FullName, correct?


I would recommend at least 128.


Well you can just put it at 255 if you want. varchars is a Variable length storage type. This means theres 1 byte which stores the actual length of the string, varchars dont use up more bites then needed so storage wise it really does not matter. This is described on the mysql page

Description can be found here http://dev.mysql.com/doc/refman/5.0/en/char.html It is illustrated halfway the page check the table.

VARCHAR values are not padded when they are stored. Handling of trailing spaces is version-dependent. As of MySQL 5.0.3, trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL. Before MySQL 5.0.3, trailing spaces are removed from values when they are stored into a VARCHAR column; this means that the spaces also are absent from retrieved values.

Conclusion: Storage wise you could always go for 255 because it wont use up additional space and you wont get intro trouble with string getting cut off.

Greetz

0

精彩评论

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