Mysql – SQL varchar character limit

characterMySQLsqlvarchar

I have read different explanations of varchar and so far I've gotten this:

CHAR( )      fixed from 0 to 255 characters long 
VARCHAR( )   variable from 0 to 255 characters long 
TINYTEXT     maximum length of 255 characters 
TEXT         maximum length of 65535 characters 
BLOB         maximum length of 65535 characters 
MEDIUMTEXT   maximum length of 16777215 characters 
MEDIUMBLOB   maximum length of 16777215 characters 
LONGTEXT     maximum length of 4294967295 characters 
LONGBLOB     maximum length of 4294967295 characters

and then this

  • char(n) variables store fixed-length character strings conisisting of exactly n characters (and, therefore, n bytes). They are limited to 8,000 characters in size.

  • nchar(n) variables store fixed-length Unicode character strings conisisting of exactly n characters (and, therefore, 2*n bytes). They are limited to 4,000 characters in size.

  • varchar(n) variables store non-fixed length character strings consisting of approximately n characters. They consume l+2 bytes of space, where l is the actual length of the string. They are limited to 8,000 characters in size.

  • nvarchar(n) variables store non-fixed length Unicode character strings consisting of approximately n characters. They consume 2*l+2 bytes of space, where l is the actual length of the string. They are limited to 4,000 characters in size.
  • varchar(max) variables store non-fixed length character strings consisting of up to 1,073,741,824 characters. They consume l+2 bytes of space, where l is the actual length of the string.
  • nvarchar(max) variables store non-fixed length Unicode character strings consisting of up to 536,870,912 characters. They consume l*2+2 bytes of space, where l is the actual length of the string.
  • text and ntext variables store up to 2GB of text data (ANSI and Unicode, respectively), but can not be used in many text operations. Therefore, they are usually only used to support legacy applications and have been replaced by the varchar(max) and nvarchar(max) data types.

So really what is the character max on varchar? Reason I am wondering is I am starting a simple little CMS and I don't want my SQL DB to overloaded with weight and as you can see for example

nvarchar(max)[length] * 2 + 2 
nvarchar being 100,000 * 2 + 2 = 200,002 bytes (what is + 2 is it literal?)

Also I've read that varchar(8,000) is better than varchar(max) so what would you suggest the type that I use for a variably changing character length, especially for content.

Best Answer

http://dev.mysql.com/doc/refman/5.0/en/char.html

  The length can be specified as a value from 0 to 255 before MySQL 5.0.3, 
  and 0 to 65,535 in 5.0.3 and later versions.

I don't think your second paste is talking about MySQL.