markzzz
markzzz

Reputation: 47947

MySql - size VARCHAR

Many people say to me that set VARCHAR(100) doesnt make sense. It the same as put 255. I'd like to know why...

Upvotes: 2

Views: 1412

Answers (2)

paxdiablo
paxdiablo

Reputation: 881103

That's rubbish. They may be talking about the fact that a varchar uses one byte for the length regardless of whether the maximum length is 100 or 255 ( lengths above that will use two bytes, up to ~64K) but they are treated differently.

If you insert a 150-character string into the former, it will be truncated to 100, that's not so for the latter case.

You should use the length that makes sense. If you have a column that will never exceed 30 characters, don't use varchar(255).

See here for the type details.

Upvotes: 3

The GiG
The GiG

Reputation: 2611

http://msdn.microsoft.com/en-us/library/aa258242%28v=sql.80%29.aspx.

VARCHAR(100) does makes sense, it says that the max size of the input is 100 chars(if you will insert a longer string it will cut it to a size 100).

VARCHAR(256) it says that the max size of the input is 256 chars.

Upvotes: 1

Related Questions