Every time is set up a new SQL table or add a new varchar
column to an existing table, I am wondering one thing: what is the best value for the length
.
So, lets say, you have a column called name
of type varchar
. So, you have to choose the length. I cannot think of a name > 20 chars, but you will never know. But instead of using 20, I always round up to the next 2^n number. In this case, I would choose 32 as the length. I do that, because from an computer scientist point of view, a number 2^n looks more even
to me than other numbers and I’m just assuming that the architecture underneath can handle those numbers slightly better than others.
On the other hand, MSSQL server for example, sets the default length value to 50, when you choose to create a varchar column. That makes me thinking about it. Why 50? is it just a random number, or based on average column length, or what?
It could also be – or probably is – that different SQL servers implementations (like MySQL, MSSQL, Postgres, …) have different best column length values.