简体   繁体   English

SQL Server 2005:将varchar转换为nvarchar问题

[英]SQL Server 2005: converting varchar to nvarchar issue

I have table with two varchar columns first_name and last_name . 我有两个varcharfirst_namelast_name

Now I need to convert these columns to nvarchar in order to support UTF-8. 现在,我需要将这些列转换为nvarchar以便支持UTF-8。

I choose nvarchar datatype in SSMS for these columns and when I try to enter some UTF-8 data, my symbols converts to question marks. 我为这些列选择了SSMS中的nvarchar数据类型,当我尝试输入一些UTF-8数据时,我的符号转换为问号。 For example, if I input йцукен (Ukrainian) it will be converted to ?????? 例如,如果我输入йцукен (乌克兰语),它将转换为?????? .

What is the problem and how to fix it? 有什么问题以及如何解决?

Thanks. 谢谢。

When you want to insert nvarchar literals into the database table, you must use the N'..' prefix. 当您想将nvarchar文字插入数据库表时, 必须使用N'..'前缀。

So use 所以用

INSERT INTO dbo.YourTable(First_Name)
VALUES(N'йцукен')

so that this string will be treated as a unicode string 这样该字符串将被视为unicode字符串

If you're not using the N'..' notation, you're really inserting a non-unicode string literal - and this will cause these conversions to ? 如果您不使用N'..'表示法,则实际上是在插入非Unicode字符串文字-这将导致这些转换为?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM