Storing a Non-English String in Table – Unicode Strings in SQL SERVER
In this article, we will discuss the overview of Storing a Non-English String in Table, Unicode Strings in SQL SERVER with the help of an example in which will see how you can store the values in different languages and then finally will conclude the conclusion as follows.
SQL Server Uses English as the default language for the database and someone wants to use other languages (e.g. Hindi, Gujarati, etc.) Words in the SQL Server table. Whenever we need to use another language SQL Server, we must use the data type NVARCHAR for the column. If we don’t use the datatype NVARCHAR, we will be not able to store non-English values.
In this example, you will see how you can store the values in the different languages in the database. So first, we will create a table as follows.
Creating a table -TestLang –
Let us create a table named ‘TestLang’.
CREATE TABLE TestLang ( LangName VARCHAR(100), Value VARCHAR(1000), NValue NVARCHAR(1000) ) GO
Inserting data –
Now, insert data of different languages in the table as follows.
INSERT INTO TestLang (LangName, Value, NValue) VALUES ('English', 'Welcome to GFG', N'Welcome to GFG'); INSERT INTO TestLang (LangName, Value, NValue) VALUES ('Gujarati', 'GFG માં આપનું સ્વાગત છે', N'GFG માં આપનું સ્વાગત છે'); INSERT INTO TestLang (LangName, Value, NValue) VALUES ('Hindi', 'GFG में आपका स्वागत है', N'GFG में आपका स्वागत है'); GO
Verifying data –
Selecting data from the table as follows.
SELECT * FROM TestLang GO
LangName Value NValue English Welcome to GFG Welcome to GFG Gujarati GFG ??? ????? ?????? ?? GFG માં આપનું સ્વાગત છે Hindi GFG ??? ???? ?????? ?? GFG में आपका स्वागत है
SQL Server Management Studio output :
You can see the given below screenshot to see the output from SQL Server Management Studio as follows.
From the above output, we could observe that when we have Unicode datatype we are able to store the non-English string. The recommendation to use NVARCHAR is when the sizes of the data in column entries vary considerably and the string length may be greater than 4,000 byte-pairs.