Skip to content
Related Articles

Related Articles

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

Improve Article
Save Article
  • Last Updated : 03 Sep, 2020
Improve Article
Save Article

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 :

    varchar(max)
    
  3. nvarchar :
    This stores variable length unicode data.
    Syntax for nvarchar is:
    Syntax :

    nvarchar
    

    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 :

Characteristicsvarcharvarchar(max)nvarchar
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.
Syntaxvarchar(n)

*n is the number of bytes

varchar(max)

*max is the maximum storage value.

nvarchar

*n is the number of bytes.

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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!