-1

What is the difference between data types var char and text in database design?

Prune
  • 75,308
  • 14
  • 55
  • 76
mfd4094
  • 35
  • 1
  • 8

3 Answers3

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
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 the CHARACTER SET (eg, 4 bytes/character for utf8mb4).
  • With CHAR, use CHARACTER 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 complex SELECTs due to how temp tables are handled.
Rick James
  • 122,779
  • 10
  • 116
  • 195
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.