views:

63

answers:

3

I was wanting to create a personal note database, to store notes in HTML or text that are quite long. What would be the difference between VARCHAR and TEXT fields, which one would be more efficient to use?

I think VARCHAR's max is 65535 characters, I can't wrap my head around if I'll contain anything larger than that though. I wonder if a certain data type can be automatically compressed, although I don't think it's that simple (since it'd take too much CPU time in real use).

+2  A: 

AFAIR TEXT is limited to 65k characters, MEDIUMTEXT is 16 millions, and LONGTEXT is 4GB max :-)

BarsMonster
BarsMonster
Def. would think about doing this, but it'd be annoying to not be able to see text and use them in queries and whatnot, I'd definitely compress a 4MB+ file though, Thanks!
John
+1  A: 

If you're not sure if the text will always be shorter than 65535 characters then do not risk to use varchar. I think that you definitely should use mediumtext or even longtext type but to increase performance place them into separate table. For example create table Notes that will contain note id, title, creation date and user that creates it and also NotesText table that will be associated with Notes but will contain only note id and your text column. That will prevent from querieng over text type columns and retrieving it from database when not really needed.

ŁukaszW.pl
I found this the most relevant answer, I quite want to put it into another table just for practise of efficiency, Thanks alot.
John
Thanks for accept ;) Good luck with your project!
ŁukaszW.pl
This is WRONG. Text in Mysql is limited to the same 65535 characters.
BarsMonster
Okay.. you told it already, he can use MEDIUMTEXT instead, but why are you writing the same thing for the third time? You think that he do not see your answer?
ŁukaszW.pl
Well, after he accepted wrong solution it was quite likely that he wouldn't notice new comment :-) Any way, it's correct now.
BarsMonster
+1  A: 

The VARCHAR maximum length isn't 65535 bytes; the maximum length of the row is that number of bytes, and the maximum length of the VARCHAR will depend on what other columns you have in the table. For that reason, if you are likely to need that many characters, you'll need a TEXT or BLOB column. These are held separately on the disk so tend to be slower (not in CPU usage but in total time).

Brian Hooper