0

I know this is a noob question and I can't find any answer on google, but I want the opinions and suggestions of expert here in sql in terms of setting the data type of columns.

Is it okay if I set all my columns to varchar? even the value of the columns are dates and numbers? Is there any difference if I use Date and Varchar?

I will totally appreciate all the answers, Thank you

4
  • Use the appropriate datatype for the column. A world of pain awaits if you don't... Commented Feb 25, 2013 at 0:59
  • ah ok sir, but can you tell wait kind of pain is that? Commented Feb 25, 2013 at 1:13
  • 1
    The kind of pain that makes you want to jab a toasting fork in your eye! But given that you won't be doing that it seems counterproductive describing it further. Commented Feb 25, 2013 at 1:34
  • Bad habits to kick : choosing the wrong data type - you should always use the most appropriate data type - that's what they're there for, after all! Commented Feb 25, 2013 at 5:37

2 Answers 2

1

The best practice is always a good place to start. Another important issue to take in to consideration is "what is this database for"? If it is for storing dates, why not use dates as the data type. As C0dem0nkey described converting data takes time and with big tables can be quite tricky.

  1. Follow best practice (they are there for a reason).
  2. What is the meaning of this database?
  3. If a choose one over the other what are the consequences?
Sign up to request clarification or add additional context in comments.

2 Comments

Ok sir, from now one I will follow the best practice for sql data types, Thank you :)
Well I am most happy to help :-D
0

i think doing so will result to an error prone system. How can you use operators on datetime if you use varchar? One way or the other, you have to convert them to datetime just to compare then convert them back to string to store again which takes much much time.

List of Best Practice MySQL Data Types

Here's a helpful post. Regards!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.