VARCHAR/CHAR 如何在 SQL Server 中存储/呈现跨国符号?
我曾经读到过,varchar (char) 用于存储每个字符 1 个字节的 ASCII 字符,而 nvarchar (varchar) 使用带有 2 个字节的 UNICODE。
但是哪个 ASCII 呢?在 SSMS 2008 R2
DECLARE @temp VARCHAR(3); --CHAR(3)
SET @temp = 'ЮЯç'; --cyryllic + portuguese-specific letters
select @temp,datalength(@temp)
-- results in
-- ЮЯç 3
更新中:哎呀,结果确实是 ЮЯс,但不是 ЮЯç。谢谢,马丁
I have used to read that varchar (char) is used for storing ASCII characters with 1 bute per character while nvarchar (varchar) uses UNICODE with 2 bytes.
But which ASCII? In SSMS 2008 R2
DECLARE @temp VARCHAR(3); --CHAR(3)
SET @temp = 'ЮЯç'; --cyryllic + portuguese-specific letters
select @temp,datalength(@temp)
-- results in
-- ЮЯç 3
Update: Ooops, the result was really ЮЯс but not ЮЯç. Thanks, Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
返回
您可以看到,根据排序规则,非 ASCII 字符可能会丢失或默默地转换为接近的等效字符。
Returns
You can see that dependant upon the collation non ASCII characters can get lost or silently converted to near equivalents.
它是 ASCII,其代码页定义了前 128 个字符 (128-255)。这是由 SQL Server 中的“排序规则”控制的,根据您使用的排序规则,您可以使用“特殊”字符的子集。
请参阅此 MSDN 页面。
It's ASCII with a codepage which defines the upper 128 characters (128-255). This is controlled by the "collation" in SQL Server, and depending on the collation you use you can use a subset of "special" characters.
See this MSDN page.