Hot Koehls
  • Email
  • Feedburner
  • Linkedin
  • Twitter
  • Home
  • About
  • Archives
  • Contact
  • Software
    • S3imple Backup
    • Twitter Feed Archiver
    • FileTime
    • Flickr API Demo
Search
Home» For techies » What 255 characters looks like

What 255 characters looks like

Posted by Frank - May 26, 2009 - For techies
8

“Should I use TEXT or VARCHAR field here?”

I’ve lost count of the number of times that I asked myself this question when putting together database structures. Since the maximum a VARCHAR can hold is 255, it becomes a question of whether or not the data you’re saving will be any longer than that. Sometimes that’s an easy call (phone number = VARCHAR; email body = TEXT), other times its blurry (verbose error logs, foreign-language data sets, user-submitted comments, etc).

“So what? Why not just use TEXT and be done with it?”

It’s true that in most cases it won’t make a difference. However, if you need to index and search the field, you should think carefully before blindly using TEXT. The data in TEXT type fields are stored outside the table itself, using only a few bytes for pointer information. This means that TEXT fields are not indexed, while VARCHAR fields are. This can have a tremendous effect on your SQL query speeds, as generally larger TEXT fields increase query time exponentially. Even if we take indexing out of the picture, the external storage of TEXT fields means that you’ll still see generally faster searches with VARCHAR.

Which brings us back to the original problem: when is a 255 character cap good enough? See for yourself. Below you’ll find a block of lorem ispum text that’s exactly 255 characters long (spaces count):

Lorem ipsum dolor sit amet, nonummy ligula volutpat hac integer nonummy. Suspendisse ultricies, congue etiam tellus, erat libero, nulla eleifend, mauris pellentesque. Suspendisse integer praesent vel, integer gravida mauris, fringilla vehicula lacinia non

If you’re like me, you’ll look at that and say, “That’s a lot more than I thought.”

Another way to look at it: RFC2822 says that a subject line may contain 998 total characters, with a max of 78 per line. Most mail clients don’t support multi-line subjects, so 78 characters is the practical limit you’ll find in most cases.

So if you ever find yourself doing that fuzzy-string-length-guestimation math in your head, bookmark this page to add a visual to the guesswork as well.

database, software development

8 comments on “What 255 characters looks like”

  1. CircusMusic says:
    May 27, 2010 at 2:52 pm

    Thanks for the simple explanation. Exactly what I needed to know.

  2. parth says:
    March 5, 2011 at 3:21 am

    Thank you very much. This just helped me out quite a bit.

  3. matt says:
    October 31, 2011 at 2:45 pm

    hmmm, SqlServer 2008 varchar(max)…

  4. Alex Railton says:
    December 5, 2011 at 11:58 pm

    I’ve never, ever left a comment on a blog before but I felt this one was worth it.

    My google search was “what does 255 characters look like”, your blog was the first result and I just wanted to thank you for explaining exactly what I needed to know. Straight to the point, and informative!

    Thanks again. :-)
    - Alex

  5. Frank says:
    December 6, 2011 at 1:02 pm

    So glad it helped Alex, and thanks for passing along the success story!

  6. diaz says:
    December 19, 2011 at 8:04 am

    If you’re like me, you’ll look at that and say, “That’s a lot more than I thought.”

    exactly! thanks anyway

  7. whiz says:
    May 15, 2012 at 7:58 pm

    Thanks for showing me what it looks like. That’s more than enough feedback from my users.

  8. Erin says:
    July 18, 2012 at 2:06 pm

    Thanks! I love the web community because folks like you put up helpful articles like this! It really does look like a lot more than I thought!

Leave a Reply Cancel reply

Categories

  • For entrepreneurs
  • For everyone
  • For techies

Latest Tweets

  • No public Tweets found

Recent Comments

  • Ηλεκτρολόγος Καρδίτσα on Find the second (or third, or fourth) occurence in a string
  • ChazzMatt on Write code like they do in Hollywood
  • ChazzMatt on Turn off AVG e-mail signature
  • Rohitash on Automating SSH or SFTP in scripts
  • kgiFozzkjk on MySQL founder Michael Widenius concerned about sale to Oracle

Recent Posts

  • How to say “GIF”
  • Display line numbers in WebSVN file detail view
  • It’s dangerous to go alone
  • Create Self-Signed Wildcard SSL Certificate
  • What comes after the yottabyte?
(c) 2013 Frank Koehl. All Rights Reserved.
  • Contact Us
  • Sitemap