Why does VARCHAR need length specification?

Fixpoint picture Fixpoint · Jul 1, 2010 · Viewed 40.8k times · Source

Why do we always need to specify VARCHAR(length) instead of just VARCHAR? It is dynamic anyway.

UPD: I'm puzzled specifically by the fact that it is mandatory (e.g. in MySQL).

Answer

Robin Day picture Robin Day · Jul 1, 2010

The "length" of the VARCHAR is not the length of the contents, it is the maximum length of the contents.

The max length of a VARCHAR is not dynamic, it is fixed and therefore has to be specified.

If you don't want to define a maximum size for it then use VARCHAR(MAX).