How to Store non-English Characters in SQL Server

Introduction

Sometime, we may need to store non-English characters or multiple languages in our database. In this article, we will have a look at how to store non-English characters in SQL Server.

VARCHAR vs NVARCHAR

We can store non-English Characters in our database table using the data type NVARCHAR(). The N stands for Unicode. It makes our string to accept Unicode data.

Example
CREATE TABLE StoreNonEnglish (ID INT PRIMARY KEY, VARCHARColumn VARCHAR(MAX), NVARCHARColumn NVARCHAR(MAX), Languages VARCHAR(MAX))

Now, lets create a table (as mentioned above code) as StoreNonEnglish, We will store our non-English characters in both VARCHARColumn and NVARCHARColumn. As the column name says, VARCHARColumn’s datatype is VARCHAR(), and NVARCHARColumn’s datatype is NVARCHAR().

Let’s insert few non-English characters into this table using T-SQL as,


INSERT INTO StoreNonEnglish 
(
	ID,
	VARCHARColumn, 
	NVARCHARColumn,
	Languages
)
VALUES
(
	1,
	'Welcome', 
	'Welcome', 
	'English'
),
(
	2,
	'நல்வரவு', 
	'நல்வரவு', 
	'Tamil'
),
(
	3,
	'स्वागत हे',
	'स्वागत हे',
	'Hindi'
),
(
	4,
	'സ്വാഗതം',
	'സ്വാഗതം',
	'Malayalam'
)

Now, once after inserting the values, Let’s run the Select T-SQL,

SELECT * FROM StoreNonEnglish
Fig 1. Not store Non-English Characters

We could see that still the non-English Characters column values (NVARCHARColumn) are not converted into Unicode values even though the datatype is NVARCHAR(). The reason is because, we also need to specify N while inserting the values into the table. As I said before, N stands for Unicode.


INSERT INTO StoreNonEnglish 
(
	ID,
	VARCHARColumn, 
	NVARCHARColumn,
	Languages
)
VALUES
(
	1,
	'Welcome', 
	N'Welcome', 
	'English'
),
(
	2,
	'நல்வரவு', 
	N'நல்வரவு', 
	'Tamil'
),
(
	3,
	'स्वागत हे',
	N'स्वागत हे',
	'Hindi'
),
(
	4,
	'സ്വാഗതം',
	N'സ്വാഗതം',
	'Malayalam'
)

Now lets run the Select T-SQL for this table, and we get the result with non-English characters from table.

Fig 2. Store Non-English Characters

GitHub: The above used T-SQL Statements are in my GitHub, Please feel free to refer.

Conclusion

To store the non-English Characters or Multi language in the database table, we need to specify the datatype which supports Unicode (N) and also while inserting into table we need to specify N (Unicode) before the value. I hope you all found this article useful. Please share your feedback in the comment section.

Other latest articles of mine

One thought on “How to Store non-English Characters in SQL Server

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Built with WordPress.com.

Up ↑

%d bloggers like this: