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.
- varchar :
Variable Character or varchar for short is a datatype that stores non-Unicode data.
The syntax for varchar is:
n – is the number of bytes. The maximum storage capacity is upto 8000 bytes.
- varchar(max) :
It stores character string data of maximum storage size 2³¹-1 bytes.
- nvarchar :
This stores variable length unicode data.
Syntax for nvarchar is:
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 :
|Storage||It 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 size||1-8000 bytes||2³¹-1 bytes||1-4000 bytes|
- CHAR vs VARCHAR in SQL
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- Mean and Mode in SQL Server
- Copy tables between databases in SQL Server using Import-and-Export Wizard
- Difference between MySQL and MS SQL Server
- Difference between Couchbase and MS SQL Server
- Create, Alter and Drop schema in MS SQL Server
- Difference between MS SQL Server and CouchDB
- Difference between MS SQL Server and IBM DB2
- Difference between Derby and MS SQL Server
- Difference between Redis and MS SQL Server
- Full join and Inner join in MS SQL Server
- Left join and Right join in MS SQL Server
- Difference between Neo4j and MS SQL Server
- Self Join and Cross Join in MS SQL Server
- Union and Union All in MS SQL Server
- SIN() and COS() Function in SQL Server
- text, ntext, binary, varbinary and varbinary(max) in MS SQL Server
- Difference between char and nchar : MS SQL Server Datatypes
- Numeric and Date-time data types in SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.