varchar 和 nvarchar 有什么区别? [英] What is the difference between varchar and nvarchar?

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

问题描述

仅仅是nvarchar 支持多字节字符吗?如果是这种情况,除了存储问题之外,使用 varchars 真的有什么意义吗?

Is it just that nvarchar supports multibyte characters? If that is the case, is there really any point, other than storage concerns, to using varchars?

推荐答案

nvarchar 列可以存储任何 Unicode 数据.varchar 列仅限于 8 位代码页.有些人认为应该使用 varchar ,因为它占用的空间更少.我相信这不是正确的答案.代码页不兼容是一种痛苦,而 Unicode 是解决代码页问题的良方.现在有了便宜的磁盘和内存,真的没有理由再浪费时间处理代码页了.

An nvarchar column can store any Unicode data. A varchar column is restricted to an 8-bit codepage. Some people think that varchar should be used because it takes up less space. I believe this is not the correct answer. Codepage incompatabilities are a pain, and Unicode is the cure for codepage problems. With cheap disk and memory nowadays, there is really no reason to waste time mucking around with code pages anymore.

所有现代操作系统和开发平台都在内部使用 Unicode.通过使用 nvarchar 而不是 varchar,您可以避免每次读取或写入数据库时​​都进行编码转换.转换需要时间,并且容易出错.从转换错误中恢复是一个非常重要的问题.

All modern operating systems and development platforms use Unicode internally. By using nvarchar rather than varchar, you can avoid doing encoding conversions every time you read from or write to the database. Conversions take time, and are prone to errors. And recovery from conversion errors is a non-trivial problem.

如果您与仅使用 ASCII 的应用程序交互,我仍然建议在数据库中使用 Unicode.操作系统和数据库整理算法将更好地与 Unicode 配合使用.当与其他系统交互时,Unicode 避免了转换问题.你将为未来做准备.并且您始终可以验证您的数据是否仅限于 7 位 ASCII 以适用于您必须维护的任何旧系统,即使同时享受完整 Unicode 存储的一些好处.

If you are interfacing with an application that uses only ASCII, I would still recommend using Unicode in the database. The OS and database collation algorithms will work better with Unicode. Unicode avoids conversion problems when interfacing with other systems. And you will be preparing for the future. And you can always validate that your data is restricted to 7-bit ASCII for whatever legacy system you're having to maintain, even while enjoying some of the benefits of full Unicode storage.

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

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