There’s VARCHAR, CHAR, TEXT, BIGTEXT, BLOB…
Which is the correct datatype to use when storing small text fields (ie. something like first_name)?
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.
“Correct” is a strong word, but most people would probably use
VARCHAR.CHARis also an option, but it’s not as frequently used in my experience. This page explains the difference.One of the notable differences between
CHARandVARCHARin the latest versions of MySQL is thatCHARis incapable of storing trailing spaces (because the column is automatically padded to its max length by spaces). So if you store something like'abc ', it will be retrieved as'abc'. This might not matter for most applications, but it’s something to keep in mind. Similarly, prior to 5.03, trailing whitespaces are stripped fromVARCHARfields before insertion. So if you need to store arbitrary byte values and don’t want to worry about different behaviors between MySQL versions, you should use one of theBLOBtypes.