请教一下什么情况下才使用char效率比较高,因为我觉得应用上varchar要比char方便得多,比如我今天下午碰到的一个情况是:数据表中有超过30个的字段是char型,并且均未填满,这样取出来做Update的时候,多余的空格是个烦人的东东,如果全部使用RTRIM()显然也浪费了很多资源,而且将char的Column作为查询关键字列的时候也经常需要RTRIM()...我看MS的许多Sample(主要是.net方面)的,数据库设计几乎没有怎么使用过char,全部都是varchar和nvarchar比较多,那么什么情况下应该使用char才合理?
---------------------------------------------------------------
the disadvantages of varchar:
1. additional storage space required to keep track of how many bytes each column contains
2. re-allocation of memory when the length of varchar column increases
3. there are also some overheads with indexing
if you have a column whose length does not vary much, it's better to use char. Otherwise, use varchar
Also, you should look at this problem from the logical point of view, if this column contains fixed length values, then use char
---------------------------------------------------------------
在类型长度比较固定或相差不大的情况下用char,不知道的时候用varchar
---------------------------------------------------------------
同一楼上的说的!
CHAR一般用在数据长度比较固定的字段.
---------------------------------------------------------------
CHAR和varchar类型长度不一样,在数据长度比较固定的字段一般用CHAR,其它时候用varchar类型。
---------------------------------------------------------------
在类型长度比较固定或相差不大的情况下用char,不知道的时候用varchar
CHAR 在查询速度上快些
VARCHAR 在使用时方便,查询速度上慢些!