SQL Server数据库字段可处理韩文和中文字符 [英] SQL Server database field to handle korean and chinese characters

查看:50
本文介绍了SQL Server数据库字段可处理韩文和中文字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server中是否可以有一个可以存储中文,韩文和欧洲字符的字段?我的汉字变成 ?????

Is it possible to have a field in SQL Server that can store Chinese, Korean and European characters? My Chinese characters just become ?????

数据类型也是 NVARCHAR .

推荐答案

NVARCHAR 是适合的类型-它以2字节Unicode格式存储所有内容.

NVARCHAR is the proper type for this - it stores everything in a 2-byte Unicode.

您需要注意的是在SQL Server Management Studio中使用 NVARCHAR 字段时-您绝对必须使用 N'....'前缀!

What you need to pay attention to is when working with NVARCHAR fields in SQL Server Management Studio - you absolutely must use the N'....' prefix in that case!

如果您使用此功能:

INSERT INTO dbo.YourTable(NVarcharColumn)
    VALUES('Some Chinese text here')

然后,SSMS将临时将您指定的字符串文字转换为 VARCHAR (非Unicode!),因此您将丢失所有Unicode编码的字符.

then SSMS will temporarily convert the string literal you specify into VARCHAR (non-Unicode!) and thus you'll loose any Unicode-encoded characters.

但是,如果您使用:

INSERT INTO dbo.YourTable(NVarcharColumn)
    VALUES(N'Some Chinese text here')

(请注意字符串文字前的 N 前缀!),然后SSMS将始终将所有内容处理为Unicode,并应保留您的中文或韩文(或其他)特殊字符.

(note the N prefix before the string literal!) then SSMS will handle everything as Unicode all the time, and your Chinese or Korean (or other) special characters should be preserved.

这篇关于SQL Server数据库字段可处理韩文和中文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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