Regarding SQL Server, I understand :
-
varmeans the memory is lazy allocated, meaning it fits to the data exactly (on insertion). -
MAXmeans there is no size restriction\limitation.
Then, is it always preferable to use MAX when using varchar, as we don’t allocate the whole size anyhow?
Should we use a constant size only if there is a constraint we want to enforce on this DB column?
There is a very good article on this subject by SO User @Remus Rusanu. Here is a snippit that I’ve stolen but I suggest you read the whole thing:
In the article he shows several examples that demonstrate that using varchar(n) typically improves performance.
You can find the entire article here.