What is the difference between varchar and nvarchar?

Overview

Varchar and nvarchar are variable-length character data types, which are used for declaring the data type of the variables used in the SQL server table. Although both of them serve the same purpose, there are still a few differences between them.

Here are a few important differences between varchar and nvarchar in the SQL server.

Character data type

  • Varchar stores Non-unicode or English character data types, and it can contain a maximum of 8000 characters. It only supports ASCII values.
  • Nvarchar stores Unicode or Non-English character data types, and it can contain a maximum of 4000 characters. It supports ASCII values as well as special characters. To support multiple languages, nvarchar is a must.

Literals

  • Literals or values in varchar are enclosed within single inverted commas. For example:
    INSERT INTO tableName VALUES ('Educative')
    Example of Varchar
    • Literals or values in nvarchar are also enclosed within single inverted commas, but they are prefixed with N. For example:
    INSERT INTO tableName VALUES (N'Educative')
    Example of NVarchar

    Storage

    • Each character in the varchar data type occupies one byte of storage.
    • Each character in the nvarchar data type occupies two bytes of storage.

    Thus, in terms of storage, nvarchar is twice as costly when compared to varchar.

    Free Resources