开发者

MySql - size VARCHAR

开发者 https://www.devze.com 2023-02-16 05:06 出处:网络
Many people say to me that set VARCHAR(100) doesnt make se开发者_如何转开发nse. It the same as put 255. I\'d like to know why...That\'s rubbish. They may be talking about the fact that a varchar uses

Many people say to me that set VARCHAR(100) doesnt make se开发者_如何转开发nse. It the same as put 255. I'd like to know why...


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消