Skip to content
Related Articles

Related Articles

Improve Article

varchar, varchar(max) and nvarchar in MS SQL Server

  • Last Updated : 03 Sep, 2020
Geek Week

We know that a database can different datatypes. Consider an organization having various databases like Employees, Departments, Finance. The employee database has a table that stores the details of each employee and employee is uniquely identified using the employee ID.

In most of the cases, an employee ID has a combination of digits and letters. How can the database store the values? It uses a special datatype named varchar or Variable Character datatype. It uses numbers and letters.

  1. varchar :
    Variable Character or varchar for short is a datatype that stores non-Unicode data.
    The syntax for varchar is:
    Syntax :
    varchar (n)

    n – is the number of bytes. The maximum storage capacity is upto 8000 bytes.

  2. varchar(max) :
    It stores character string data of maximum storage size 2³¹-1 bytes.

    Syntax :

  3. nvarchar :
    This stores variable length unicode data.
    Syntax for nvarchar is:
    Syntax :

    n – is the number of bytes and can store upto 4000 bytes. If the length for the datatype isn’t specified, it takes the default value of 1. These datatypes can be used while creating a table.

An overview of these datatypes :

StorageIt stores variable length, non unicode character string data.It stores variable length non-unicode, character string data.It stores variable length, unicode character string data.

*n is the number of bytes


*max is the maximum storage value.


*n is the number of bytes.

Storage size1-8000 bytes2³¹-1 bytes1-4000 bytes

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

My Personal Notes arrow_drop_up
Recommended Articles
Page :