varchar vs char [英] varchar vs char

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

问题描述

两种数据类型有什么区别?

解决方案

Techie写道:

这两种数据类型的区别是什么?



var

希望它有所帮助,


Jan M. Nelken


Techie写道:

两种数据类型有什么区别?



我发现的主要行为差异是尾随

空白的影响。使用varchar,除非您将它们放在数据

项目中,否则没有。使用char,数据总是填充到

数据项的长度。这可能会在许多不同的背景下咬你,并且需要自由应用rtrim。 IMHO char(n)应该只在您确定现在和将来数据总是n个字符的时候才会确定。在

中,每个其他情况都应使用varchat(n)。


char是固定长度的字符数据类型, varchar是一个

可变长度的字符数据类型。


因为char是固定长度的数据类型,所以char的存储大小

值等于此列的最大大小。因为varchar是可变长度数据类型,所以varchar值的存储大小是

输入数据的实际长度,而不是这个

列。


当列中的数据条目与

相同时,您可以使用char。

当列中的数据条目预期时,你可以使用varchar

大小差别很大。

http://www.mssqlcity.com/FAQ/General...vs_varchar.htm

what''s the difference of the two data types?

解决方案

Techie wrote:

what''s the difference of the two data types?


var
Hope it helps,

Jan M. Nelken


Techie wrote:

what''s the difference of the two data types?


The major behavioral difference I have found is the effect of trailing
blanks. With varchar, there are none unless you place them in the data
item. With char, the data is always padded out to the length of of the
data item. This can bite you in many different contexts and requires
liberal application of rtrim. IMHO char(n) should only when you certain
that now and in the future the data will always be n characters long. In
every other case varchat(n) should be used.


The char is a fixed-length character data type, the varchar is a
variable-length character data type.

Because char is a fixed-length data type, the storage size of the char
value is equal to the maximum size for this column. Because varchar is
a variable-length data type, the storage size of the varchar value is
the actual length of the data entered, not the maximum size for this
column.

You can use char when the data entries in a column are expected to be
the same size.
You can use varchar when the data entries in a column are expected to
vary considerably in size.

http://www.mssqlcity.com/FAQ/General...vs_varchar.htm


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

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