Reading this question, a doubt popped into my head:
So how much bytes does TEXT actually occupy? ~65KB or number of chars used + 1?
TEXT has a fixed max size of 2¹⁶-1 = 65535 characters. VARCHAR has a variable max size M up to M = 2¹⁶-1 . So you cannot choose the size of TEXT but you can for a VARCHAR . The other difference is, that you cannot put an index (except for a fulltext index) on a TEXT column.
In most circumstances, VARCHAR provides better performance, it's more flexible, and can be fully indexed. If you need to store longer strings, use MEDIUMTEXT or LONGTEXT, but be aware that very large amounts of data can be stored in columns of these types.
The CHAR is fixed-length character type while the VARCHAR and TEXT are varying length character types. Use VARCHAR(n) if you want to validate the length of the string ( n ) before inserting into or updating to a column. VARCHAR (without the length specifier) and TEXT are equivalent.
TEXT is the family of column type intended as high-capacity character storage. The actual TEXT column type is of four types-TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. The four TEXT types are very similar to each other; the only difference is the maximum amount of data each can store.
TEXT is a variable length datatype, with a maximum of 65,000 characters.
LONGTEXT can be used for over 4 trillion characters.
To answer your question: it's a variable lenght, and it will only occupy the amount of characters you store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With