SQL Varchar(max) 和 nvarchar(max) 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30860230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between Varchar(max) and nvarchar(max)
提问by selva
I came across a question while buidling schema for my application.
我在为我的应用程序构建架构时遇到了一个问题。
When to use varchar(max)
and nvarchar(max)
. I mean the exact use cases where it should be applied. I have surfed in net too but I was able to get the exact answer.
何时使用varchar(max)
和nvarchar(max)
。我的意思是应该应用它的确切用例。我也上网冲浪,但我能够得到确切的答案。
Could anyone suggest some exact usecase.
任何人都可以提出一些确切的用例。
回答by marc_s
This is for Microsoft SQL Server:
这是针对 Microsoft SQL Server 的:
NVARCHAR
is Unicode- 2 bytes per character, therefore max. of 1 billion characters; will handle East Asian, Arabic, Hebrew, Cyrillic etc. characters just fine.
NVARCHAR
是Unicode- 每个字符 2 个字节,因此最大。10 亿个字符;将处理东亚、阿拉伯、希伯来、西里尔等字符就好了。
VARCHAR
is non-Unicode- 1 byte per character, max. capacity is 2 billion characters, but limited to the character set you're SQL Server is using, basically - no support for those languages mentioned before
VARCHAR
就是非Unicode-每个字符1个字节,最大 容量为 20 亿个字符,但仅限于 SQL Server 使用的字符集,基本上 - 不支持前面提到的那些语言
回答by Mukesh Kalgude
Varchar(max)
Varchar(最大)
Varchar fields can be of any size up to a limit, which varies by databases: an Oracle 9i database has a limit of 4000 bytes, a MySQL database has a limit of 65,535 bytes (for the entire row) and Microsoft SQL Server 2005 has a limit of 8000 characters (unless varchar(max) is used, which has a maximum storage capacity ...
Varchar 字段可以是任意大小,最多可有限制,该限制因数据库而异:Oracle 9i 数据库的限制为 4000 字节,MySQL 数据库的限制为 65,535 字节(对于整行),Microsoft SQL Server 2005 的限制为限制为 8000 个字符(除非使用 varchar(max),它具有最大存储容量...
nvarchar(max)
nvarchar(最大)
abcdefg n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.
abcdefg n 定义字符串长度,可以是 1 到 4,000 之间的值。max 表示最大存储大小为 2^31-1 字节(2 GB)。存储大小(以字节为单位)是输入数据实际长度的两倍 + 2 个字节。nvarchar 的 ISO 同义词是不同的国家字符和不同的国家字符。
回答by Jens
You should use nvarchar if you have to store unicode char. If you only store non-unicode-char you can use varchar.
如果必须存储 unicode char,则应使用 nvarchar。如果您只存储非 unicode-char,则可以使用 varchar。
回答by Hassan Habib
nvarchar is for unicode data, whilst varchar is uses only up to 8-bit codepage. Use cases: varchar is good when you're dealing with Latin letters in general, so let's say you have a blog and the language used to write to this blog is English, at this case varchar is a good option. nvarchar is good when you're building a multilingual application, so you're using characters like Mandarin, Arabic ..etc.
nvarchar 用于 unicode 数据,而 varchar 仅使用最多 8 位代码页。用例: varchar 一般适用于处理拉丁字母,因此假设您有一个博客,并且用于撰写此博客的语言是英语,在这种情况下 varchar 是一个不错的选择。nvarchar 在您构建多语言应用程序时非常有用,因此您可以使用普通话、阿拉伯语等字符。
Hope this helps.
希望这可以帮助。