For example on a varchar datatype, I’m allowing usernames to a maximum number of characters of 25. Does that mean the optimal column is varchar(25)?
EDIT: Does it also mean that length of string = size of string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The size of a VARCHAR column in MySQL is not actually that important! Under most (all?) storage engines, the amount of storage required for each row does not increase as you the size of the column goes up to a maximum of
VARCHAR(255). Using aVARCHAR(256)or larger will use a single extra byte per row, which still isn’t a lot. (At that point you may want to think about using aTEXTcolumn anyway.)As such, be generous with your column sizes. Avoid hard-coding non-technical limits (like a limit of 25 characters in a username) into the database — if you change your mind later it’s much easier to just change your validation code than it is to alter a potentially very large table. For usernames, for instance, I’d just set the column size to something medium-ridiculous like
VARCHAR(64)to allow for future expansion. Just make sure that, if the same “data type” (e.g, username) appears elsewhere in the database, you use the same generous size consistently.