SQL中的CHAR数据类型是否过时?你什么时候使用它? [英] Is the CHAR datatype in SQL obsolete? When do you use it?

查看:271
本文介绍了SQL中的CHAR数据类型是否过时?你什么时候使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题几乎构成了这个问题。我多年没有使用CHAR。现在,我对一个有CHAR的数据库进行反向工程,主键,代码等。
CHAR(30)列怎么样?

The title pretty much frames the question. I have not used CHAR in years. Right now, I am reverse-engineering a database that has CHAR all over it, for primary keys, codes, etc. How about a CHAR(30) column?

编辑:
所以一般的意见似乎是CHAR如果完全正确的某些事情。然而,我认为你可以设计一个数据库模式,不需要这些特定的东西,因此不需要固定长度的字符串。有了bit,uniqueidentifier,varchar和文本类型,似乎在一个良好规范化的模式中,你会得到一些优雅,当你使用编码的字符串值时,你不会得到。思考固定长度,没有进攻意味着,似乎是大型机天的遗物(我自己学习了RPG II)。我相信它已经过时了,我没有听到你说的另一个令人信服的论据。

So the general opinion seems to be that CHAR if perfectly fine for certain things. I, however, think that you can design a database schema that does not have a need for "these certain things", thus not requiring fixed-length strings. With the bit, uniqueidentifier, varchar, and text types, it seems that in a well-normalized schema you get a certain elegance that you don't get when you use encoded string values. Thinking in fixed lenghts, no offense meant, seems to be a relic of the mainframe days (I learned RPG II once myself). I believe it is obsolete, and I did not hear a convincing argument from you claiming otherwise.

推荐答案

其中数据的性质决定了字段的长度,我使用CHAR。否则为VARCHAR。

Where the nature of the data dictates the length of the field, I use CHAR. Otherwise VARCHAR.

这篇关于SQL中的CHAR数据类型是否过时?你什么时候使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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