• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which one between varchar and text is good for storing variable length String in mysql db?

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I have a question in my web application there is some fields whose length is not fixed but its within a range

My Question is which approach I should use Varchar with some range specified or using text for that fields

Why I have doubt is some times it can be 10 charcters and sometimes 50 charcters which one I should use or I simple declare that field as type Text in mysql?


Thanks
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the values you're going to store to that column are sometimes 10 characters and sometimes 50 characters long, it would seem to me that they're actually two different kinds of data, and you should perhaps change your database model to store them in two different columns.

If, on the other hand, the length of all values varies between 10 and 50 characters, then a VARCHAR(50) would work quite nicely for that. If the 50 character limit could be (significantly) increased in the future, then perhaps you should use TEXT instead. But it's you who knows the data, so you need to decide that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic