What is the difference between data types var char and text in database design?
Asked
Active
Viewed 1,726 times
-1
-
http://dev.mysql.com/doc/refman/5.7/en/string-types.html – juergen d Aug 20 '16 at 14:14
-
2Possible duplicate of [varchar vs text - MySQL](http://stackoverflow.com/questions/5739172/varchar-vs-text-mysql) – Wickramaranga Aug 20 '16 at 14:15
-
1@Wickramaranga -- that particular Q&A is a shambles of multiple questions and dubious answers. I added [_my own answer_](http://stackoverflow.com/a/39059399/1766831), which does address the current question. – Rick James Aug 20 '16 at 22:53
-
@juergend You should post this as an answer, with a bit of expanded commentary as well as just the link. – Vince Bowdren Aug 22 '16 at 10:20
-
Removed redundancies – Prune Aug 23 '16 at 21:07
3 Answers
0
The main difference is than TEXT has a fixed max size of 2¹⁶-1 = 65535 characters. VARCHAR has a variable max size M up to M = 2¹⁶-1.

tenyasha
- 1
- 1
-
Close -- The limit for `TEXT` is in _bytes_; `VARCHAR` is in _characters_. – Rick James Aug 20 '16 at 22:38
0
There are very few differences between VARCHAR
and TEXT
. Most are not really important.
Summary of *TEXT
, CHAR
, and VARCHAR
:
- Never use
TINYTEXT
. - Almost never use
CHAR
-- it is fixed length; each character is the max length of theCHARACTER SET
(eg, 4 bytes/character for utf8mb4). - With
CHAR
, useCHARACTER SET ascii
unless you know otherwise. VARCHAR(n)
will truncate at n characters;TEXT
will truncate at some number of bytes. (But, do you want truncation?)*TEXT
may slow down complexSELECTs
due to how temp tables are handled.

Rick James
- 135,179
- 13
- 127
- 222
0
VARCHAR column can be given with any size, but it is limited by the maximum size of a single row of data (including all columns), which is 64KB (2¹⁶-1) .TEXT columns do not add to the maximum row size, because the actual text is not stored with the rest of the row.

Vinay Naryana
- 1
- 1