Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

VARCHAR vs. TEXT

Hi all, I'd like some more information (in a simple to understand beginner's level format) on the differences between when to use VARCHAR vs. TEXT. I understand that VARCHAR stands for Variable Characters, but I don't understand the need to differentiate a short amount of text vs. a longer amount of text. I also don't understand why the ability to be variable is a really cool feature of VARCHAR.

1 Answer

Steven Parker
Steven Parker
231,261 Points

The value of VARCHAR is conservation of space. If text fields were not variable, then a column capable of storing 100 characters would require 100 characters for every row of the table.

The variability allow each stored value to take up only as much storage as it needs (plus a little overhead). So if the column we were talking about had just a few rows where it used 100 characters, but had thousands of rows where it needed only a dozen, the difference in storage space would be quite significant.