varchar列的大小 [英] Size of varchar columns

查看:94
本文介绍了varchar列的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sql server中,如果我将varchar列的长度定义为32或128,会有所不同吗?

In sql server does it make a difference if I define a varchar column to be of length 32 or 128?

推荐答案

A

A varchar is a variable character field. This means it can hold text data to a certain length. A varchar(32) can only hold 32 characters, whereas a varchar(128) can hold 128 characters. If I tried to input "12345" into a varchar(3) field; this is the data that will be stored:

"123"

"45"将被截断"(丢失).

The "45" will be "truncated" (lost).

当您知道某个字段最大只能(或仅应该 )一定长度时,它们非常有用.例如:邮政编码或州名缩写.实际上,它们通常用于几乎所有类型的文本数据(例如名称/地址/等等),但是在这些情况下,您必须注意,提供的数字对于要填充的数据类型来说是合理的最大值.该列.

They are very useful in instances where you know that a certain field will only be (or only should be) a certain length at maximum. For example: a zip code or state abbreviation. In fact, they are generally used for almost all types of text data (such as names/addresses/et cetera) - but in these instances you must be careful that the number you supply is a sane maximum for the type of data that will fill that column.

但是,在使用它们时,还必须小心,仅允许用户输入该字段将支持的最大字符数.否则,在截断用户输入时可能会造成混乱.

However, you must also be careful when using them to only allow the user to input the maximum amount of characters that the field will support. Otherwise it may lend to confusion when it truncates the user's input.

这篇关于varchar列的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆