Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server database field to handle korean and chinese characters

Tags:

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

The datatype is NVARCHAR as well.

like image 412
Alessandro Avatar asked Jan 19 '11 14:01

Alessandro


People also ask

How does SQL Server handle Chinese characters?

Answers. Please ensure that you place "N" prefix while inserting UNICODE character or string into table with column as NVARCHAR type. Refer the below 2 Insert statements. The second one does not have capital N before the unicode string.

Can varchar store Chinese characters?

VARCHAR or NVARCHAR ? If it is VARCHAR with SQL_Latin1_General_CP1_CI_AS with , DB CAN NOT save Chinese. If it is NVARCHAR, DB can save Unicode include Chinese. OutSystems use NVARCHAR type, so it can handle Chinese well.

How do I select Chinese characters in SQL?

This works for me in SQL Server: CREATE TABLE #temp (a nvarchar(10) NOT NULL) INSERT #temp (a) VALUES(N'村'), (N'邨') SELECT * FROM #temp WHERE a = N'村'

How does SQL Server handle special characters?

Use braces to escape a string of characters or symbols. Everything within a set of braces in considered part of the escape sequence. When you use braces to escape a single character, the escaped character becomes a separate token in the query. Use the backslash character to escape a single character or symbol.


1 Answers

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

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!

If you use this:

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

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

However, if you use:

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

(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.

like image 104
marc_s Avatar answered Sep 29 '22 14:09

marc_s