In a MySQL table, I have several columns – some containing strings, some dates or numbers. I have always just made each field varchar(200). What are the benefits of creating more appropriate field types? Will select queries become faster?
Share
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.
Using datatypes means that you’ll be able to actually use the data in a meaningful way. For example, you can do date arithmetic (using DATE_ADD, for example).
It also means that ordering by numbers will work as expected (it won’t with strings).
It also allows mysql to choose the appropriate amount/type of storage for the data you’re representing.
There are many reasons, not least that it makes it easier for anyone else using your schema to know what kinds of values to expect. It also allows mysql to do validation on your data (what happens if your “date” column contains “Once in a blue moon”?)