What are the difference between VARCHAR AND NVARCHAR in sql server?
- VARCHAR is non-unicode character type with variable length
- NVARCHAR is unicode character type with variable length
- VARCHAR occupies 1 byte per character.
- for example: DECLARE @NAME VARCHAR(10)='JAYENDRA'
- occupies 8 bytes
- NVARCHAR occupies 2 byte per character.
- for example: DECLARE @NAME NVARCHAR(10)='JAYENDRA'
- occupies 16 bytes
- use VARCHAR type when your column have only non-unicode character data only like any character which has ascii value 0 to 255
- use NVARCHAR type when you table column contains unicode character data like any other language character ex. gujarati or hindi
- Occupies number of bytes equal to the number of Characters entered and 2 bytes extra for defining offset.
- Occupies number of bytes equal to the number of Characters entered * 2 (twice of character) and 2 bytes extra for defining offset.