views:

96

answers:

2

When I have a text field, I generally store it as varchar. But then I encounter the issue of how do I know the limit I should place? Estimating how much text a user will type seems very imprecise.

As varchar uses as much space as needed, is it better to set the limit to far greater than you estimate?

Is there any disadvantage to using the various Text datatypes? Can it be searched using the "LIKE" operator and wildcards?

A: 

I think there could be cases where it's better to shrink the value of varchar. But in many cases it's fine to use 255 as it's limit.

Varchar can be searched with LIKE and wildchards.

Ólafur Waage
I was thinking using a limit more in the region of 1000s. For some text fields, users enter a large amount of text, which is why I find estimating difficult.
me_here
A: 

If the user is likely to type more than 255 characters (the usual limit for a VARCHAR) then you need TEXT, but it can be indexed. MySQL has a FULLTEXT index for TEXT columns, which works reasonably well, but wouldnt be as quick as a CHAR or VARCHAR column.

Why not try a test out on your local machine with some dummy data to see how the performance compares, and if you can do the queries you would like quickly enough?

jgubby