Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode- VARCHAR and NVARCHAR

Tags:

sql

sql-server

-- Creating Table 

  Create Table Test1
  (
    id Varchar(8000)
  )

-- Inserting a record  
Insert into Test1 Values ('我們的鋁製車架採用最新的合金材料所製成,不但外型輕巧、而且品質優良。為了達到強化效果,骨架另外經過焊接和高溫處理。創新的設計絕對能充分提升踏乘舒適感和單車性能。');

As I have defined data type of id as Varchar. The data is stored as ?????.

Do I have to use NVARCHAR..? What is Difference between VarChar and Nvarchar(). Please explain about UNIcode as well.

like image 251
Hari Gillala Avatar asked Oct 21 '11 19:10

Hari Gillala


5 Answers

Despite the collation of your database. Use nvarchar to store UNICODE. Embbed your Unicode value in N'[value]'

INSERT INTO ... VALUES
('Azerbaijani (Cyrillic)', N'Aзәрбајҹан (кирил әлифбасы)', 'az-cyrl')

In DB: 59   Azerbaijani (Cyrillic)  Aзәрбајҹан (кирил әлифбасы) az-cyrl

Important is the N prefix!

Valid for MS SQL 2014 I am using. Hope this helps.

like image 182
Andreas Ahlen Avatar answered Oct 09 '22 01:10

Andreas Ahlen


The column type nvarchar allows you to store Unicode characters, which basically means almost any character from almost any language (including modern languages and some obsolete languages), and a good number of symbols too.

like image 32
Mark Byers Avatar answered Oct 20 '22 21:10

Mark Byers


also it is required to prefix N before your value. example Insert into Test1 Values (N'我們的鋁製車架採用最新的合金材料所製成,不但外型輕巧、而且品質優良。為了達到強化效果,骨架另外經過焊接和高溫處理。創新的設計絕對能充分提升踏乘舒適感和單車性能。'); or programatically use preparedstatement with bind values for inserting and updating natural characterset

like image 6
Rajesh Kumar Avatar answered Oct 20 '22 19:10

Rajesh Kumar


Nvarchar supports UNICODE. SO yes. you need to have the column as nvarchar and not varchar.

like image 4
Vivek Viswanathan Avatar answered Oct 20 '22 19:10

Vivek Viswanathan


Yes you have to use nvarchar or use a collation for the language set you want. But nvarchar is preferred. Goodgle can tell you what this stuff means.

like image 2
HLGEM Avatar answered Oct 20 '22 20:10

HLGEM