30

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?

Dale K
  • 25,246
  • 15
  • 42
  • 71
pavanred
  • 12,717
  • 14
  • 53
  • 59
  • How do you know it didn't work? Perhaps your query program can't print Unicode characters. What program is showing the "????"? How do you know it can show Unicode properly? – S.Lott May 21 '10 at 11:48
  • In SQL management studio, when i query out the row then it displays as '????' and the same reflects in my program. – pavanred May 21 '10 at 14:12

3 Answers3

56

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').)

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • +1 for the example. Thanks Guffa. There was another thread which suggested to prefix 'N'. But, I was not quite sure where exactly to do it. – pavanred May 21 '10 at 14:17
  • I have already used the type `ntext` , but always show `????` when I'm trying to add Arabic characters – abdou_dev Sep 22 '20 at 10:18
7

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'حسن')
Dale K
  • 25,246
  • 15
  • 42
  • 71
0

If you are trying to load data directly into the database like me, I found a great way to do so by creating a table using Excel and then export as CSV. Then I used the database browser SQLite to import the data correctly into the SQL database. You can then adjust the table properties if needed. Hope this would help.

Dale K
  • 25,246
  • 15
  • 42
  • 71