Vaibhav Jain
Vaibhav Jain

Reputation: 34447

Multiple languages in varchar in SQL Server

Can we store multilingual text in varchar? I used to believe that for these scenarios, we need to have a nvarchar, but when I tried the below code it worked fine.

DECLARE @name VARCHAR(100)
SET @name='Hej mit navn er Vaibhav'
SELECT @name

So should I take varchar or nvarchar to store multilingual text.

Upvotes: 2

Views: 6413

Answers (2)

Kevin Aenmey
Kevin Aenmey

Reputation: 13429

nvarchar stores Unicode characters (which supports many more characters), varchar does not. Since 'Hej mit navn er Vaibhav' does not contain any Unicode characters, it works just fine.

So should I take varchar or nvarchar to store multilingual text.

That depends on your situation. nvarchar takes twice as much space as varchar so if you have a large database and you will never need to store the extra character sets, varchar would make sense. However space may not be an issue for you with a smaller database and you may prefer to use the extra space to allow for Unicode characters in the future.

Since specifically ask about multilingual text, I would say it is likely you would encounter characters that varchar cannot store.

Upvotes: 3

Madhivanan
Madhivanan

Reputation: 13700

Use Nvarchar datatype

DECLARE @name NVARCHAR(100) 
SET @name=N'Hej mit navn er Vaibhav' 
SELECT @name 

Upvotes: 1

Related Questions