Main Difference
Varchar and nvarchar are data types in SQL Server. The main difference between varchar and narchar is that the narchar is used for storing Unicode characters while varchar is used for storing Non-Unicode characters. Data storage is 1 byte per character in varchar while data storage in nvarchar is 2 bytes per character. In field definition varchar supports up to 8000 characters while nvarchar supports up to 4000 characters.
Varchar
Varchar is a data type of AQL Server relates to the variable characters. Non-Unicode characters are stored by using varchar. Memory allocation in varchar is according to the inserted characters. In field definition varchar supports up to 8000 characters.
Nvarchar
Nvarchar is a data type of SQL Server relates to the variable characters. Unicode characters are stored by using nvarchar. Multiple languages can be stored in data base. If others languages are being used, nvarchar will take twice space for storing extended set of characters. In filed definition nvarchar supports up to 4000 characters.
Key Differences
- Narchar is used for storing Unicode characters while varchar don’t store Unicode characters.
- Varchar is used for storing Non-Unicode characters while nvarchar don’t store Non-Unicode characters.
- Data storage 1 byte per character in varchar while in narchar data storage is not 1 byte per character.
- Data storage in nvarchar is 2 bytes per character while in varchar data storage is not 2 bytes per character.
- In field definition varchar supports up to 8000 characters while nvarchar supports up to 4000 characters.
- Memory allocation in varchar is equal to inserted number of characters plus two extra bytes for offset while in nvarchar memory allocation is equal to twice of the inserted number of characters plus with extra bytes for offset.
- If there is Unicode characters to be stored in column or variable then we use varchar while on the other side if there are Non-Unicode to be stored in column or variable then we use nvarchar.
- In the variable declaration or column definition, if the the valve n of the optional parameter is not specified then it is considered to be as 1 for varchar and 2 for nvarchar.