Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert Arabic characters into SQL database?

How can I insert Arabic characters into a SQL Server database? I tried to insert Arabic data into a table and the Arabic characters in the insert script were inserted as '??????' in the table.

I tried to directly paste the data into the table through SQL Server Management Studio and the Arabic characters was successfully and accurately inserted.

I looked around for resolutions for this problems and some threads suggested changing the datatype to nvarchar instead of varchar. I tried this as well but without any luck.

How can we insert Arabic characters into SQL Server database?

like image 432
pavanred Avatar asked May 21 '10 11:05

pavanred


People also ask

How do I add Arabic characters to SQL Developer?

In SQL Developer go to Tools / Preferences / Environment / Encoding and select UTF-8 . Set an Environment Variable to NLS_LANG=ARABIC_AMERICA. AL32UTF8 or similar, you can also do NLS_LANG=. AL32UTF8 in order to keep default/existing language and territory.

How do I add another language to SQL Server?

The simplest solution is to insert data in table as NVARCHAR data type, like below. Show activity on this post. @DipGirase - You should be able to mix unicode characters from any language, for example insert into MyTable(MyColumn) values (N'हैलो दुनिया english АВГДЄЅЗИѲ àèìòù') .

What special characters are allowed in SQL?

The rules for naming database objects (such as tables, columns, views, and database procedures) are as follows: Names can contain only alphanumeric characters and must begin with an alphabetic character or an underscore (_). Database names must begin with an alphabetic character, and cannot begin with an underscore.


2 Answers

For the field to be able to store unicode characters, you have to use the type nvarchar (or other similar like ntext, nchar).

To insert the unicode characters in the database you have to send the text as unicode by using a parameter type like nvarchar / SqlDbType.NVarChar.

(For completeness: if you are creating SQL dynamically (against common advice), you put an N before a string literal to make it unicode. For example: insert into table (name) values (N'Pavan').)

like image 194
Guffa Avatar answered Oct 11 '22 13:10

Guffa


Guess the solation is first turn on the field to ntext then write N with the value. For example

insert into eng(Name) values(N'حسن') 
like image 22
عدنان الاصبحي Avatar answered Oct 11 '22 13:10

عدنان الاصبحي