SQL Speaks Hindi Too: The Power of Unicode Explained – SQL Circuit

SQL Speaks Hindi Too: The Power of Unicode Explained

Did you know your SQL Server can fluently understand and store languages like Hindi, Tamil, Japanese, or even emojis? Gone are the days when databases were limited to plain English. Thanks to Unicode, SQL Server now speaks the language of the world—literally! In this article, we’ll uncover how Unicode and Non-Unicode data types work, why using N before a string makes all the difference, and how one line of code can preserve the soul of a sentence, whether it’s “Time and tide wait for none” or “समय और लहरें किसी का इंतजार नहीं करतीं।”

What is Unicode?

Unicode is a character encoding standard that supports virtually all languages and scripts globally, including Hindi, Chinese, Arabic, and emojis. In SQL Server, Unicode is stored using data types like:

  • NCHAR
  • NVARCHAR
  • NTEXT (deprecated)

These data types use 2 bytes per character, allowing storage of multilingual data reliably.

What is Non-Unicode?

Non-Unicode data types are limited to ASCII characters (like A–Z, 0–9, symbols) and do not support regional languages. In SQL Server, these are:

  • CHAR
  • VARCHAR
  • TEXT (deprecated)

They use 1 byte per character, which saves space but lacks support for special scripts or non-Latin languages.

Use Unicode types (NVARCHAR, NCHAR) when storing multilingual text or special characters, such as Hindi or emojis. If your data is strictly English-based, Non-Unicode types (VARCHAR, CHAR) save space and slightly improve performance. Choose based on language needs and future scalability.

Practical Example: Hindi-English Quote

Let’s take the famous quote:
English: “Time and tide wait for none.”
Hindi: “समय और लहरें किसी का इंतजार नहीं करतीं।”

English


--Testing of English language with Unicode & Non UniCode Data Type
-- Unicode example (supports English)
DECLARE @QuoteEnglish_With_UniCode NVARCHAR(100)
SET  @QuoteEnglish_With_UniCode = 'Time and tide wait for none.';

-- Non-Unicode example (supports English)
DECLARE @QuoteEnglish_Without_UniCode VARCHAR(100) 
SET @QuoteEnglish_Without_UniCode= 'Time and tide wait for none.';


SELECT @QuoteEnglish_With_UniCode AS 'Unicode supports English'
SELECT @QuoteEnglish_Without_UniCode AS 'Non Unicode also supports English'

Hindi


--Testing of Hindi language with Unicode & Non UniCode Data Type
-- Unicode example (supports Hindi)
DECLARE @QuoteHindi_With_UniCode NVARCHAR(500)
SET @QuoteHindi_With_UniCode = N'समय और लहरें किसी का इंतजार नहीं करतीं.';

-- Non-Unicode does not support Hindi
DECLARE @QuoteHindi_Without_UniCode VARCHAR(500) 
SET @QuoteHindi_Without_UniCode = N'समय और लहरें किसी का इंतजार नहीं करतीं.';


SELECT @QuoteHindi_With_UniCode AS 'Unicode supports Hindi'
SELECT @QuoteHindi_Without_UniCode AS  'Non Unicode does not supports Hindi'

Leave a Reply

Your email address will not be published. Required fields are marked *