What should be the typical length of the full username in the database

Possible duplicate:
List of standard lengths for database fields

In a simple way, what should be the typical length of the allowed "full name" of the user in the database?

When I create a users table, I usually set it as varchar 31 or 32 (depending on performance). What are you guys using and what is the standard / typical convention.


Sidenote: I never run into the problem of email length (since I set it to 254) and password (hash, length 32).

+4
source share
4 answers

The maximum average varchar field allows (254?).

You gain nothing by making it arbitrarily shorter. Fine-grained size control by numbers and symbols is more or less a relic of the past when each byte mattered. It can make a difference today - if you are dealing with tens or hundreds of millions of rows or thousands of queries per second. For your average database (i.e. 99% of them), performance comes from proper indexing and queries, NOT making your rows a couple of bytes less.

Limit the length of the field only when there is some formal specification specifying the maximum length, for example 13 digits for the EAN code or 12 characters for ISIN.

+6
source

A full name is always a calculated column consisting of the first, middle, last, prefix, suffix, degree, last name, etc. in my projects. The list of individual columns is determined by the target locale of the application. The "Full Name" display length is the norm that is contained in the design of the application, and not in the database. In SQL Server, there is no space saving between varchar (32) and varchar (256). Varchar (256) is my choice.

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

You always assign an identifier to a user so you can join and search using the identifier instead of the full name, right?

+2
source

I would recommend at least 128.

+1
source

Well, you can just put it at 255 if you want. varchars is a variable length storage type. This means that 1 byte, which stores the actual string length, varchars do not use more bites, and then it is necessary that the storage be wise, it really does not matter. This is described on the mysql page.

The description can be found here http://dev.mysql.com/doc/refman/5.0/en/char.html This is shown halfway through the page to check the table.

VARCHAR values โ€‹โ€‹are not supplemented if they are stored. Processing trailing spaces is version dependent. Starting with MySQL 5.0.3, trailing spaces are preserved when storing values โ€‹โ€‹and obtained in accordance with standard SQL. Prior to MySQL 5.0.3, trailing spaces are removed from the value when they are stored in the VARCHAR column; this means that spaces are also missing values.

Conclusion: Storage is reasonable, you can always use 255, because it will not use additional space, and you will not get problems entering a line with disconnecting the line.

Greetz

0
source

All Articles