Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store arabic in SQL database

I tried to store Arabic string in SQL 2008 database but it converted to " question mark " why ? and what should I do ?

like image 218
kartal Avatar asked Aug 24 '10 19:08

kartal


People also ask

How do I store different languages in SQL Server?

To store data of other language than English in SQL Server, we use Unicode compatible data types in the column such as nvarchar, nchar, ntext otherwise proper data is not stored in the database. Also while inserting data into those columns we prefix the data with “N” character.

What is the difference between varchar and nvarchar?

The key difference between varchar and nvarchar is the way they are stored, varchar is stored as regular 8-bit data(1 byte per character) and nvarchar stores data at 2 bytes per character. Due to this reason, nvarchar can hold upto 4000 characters and it takes double the space as SQL varchar.

Does SQL use UTF 8?

SQL Server 2019 introduces support for the widely used UTF-8 character encoding. This has been a longtime requested feature and can be set as a database-level or column-level default encoding for Unicode string data.


1 Answers

You need to choose an Arabic collation for your varchar/char columns or use Unicode (nchar/nvarchar)

CREATE TABLE #test ( col1 VARCHAR(100) COLLATE Latin1_General_100_CI_AI, col2 VARCHAR(100) COLLATE Arabic_CI_AI_KS_WS, col3 NVARCHAR(100) ) INSERT INTO #test VALUES(N'لا أتكلم العربية',N'لا أتكلم العربية',N'لا أتكلم العربية') 

Note the N before values in insert statement above. If you do not mention it, system will treat the values as Varchar, not NVarchar.

SELECT * FROM #test 

Returns

col1                           col2                           col3 ------------------------------ ------------------------------ ------------------------------ ?? ????? ???????               لا أتكلم العربية               لا أتكلم العربية 

To see a list of Arabic collations use

SELECT name, description  FROM fn_helpcollations()  WHERE name LIKE 'Arabic%' 
like image 127
Martin Smith Avatar answered Sep 22 '22 03:09

Martin Smith