In this article i will differentiate between varchar, nvarchar data type.
About the Varchar:
- It is a variable that has a length data type.
- It is use to store non-Unicode characters.
- It Occupy 1 byte of space for each character.
example :
DECLARE @name VARCHAR(20)
SET @name = 'Rizwan'
SELECT @name AS 'Name', DATALENGTH(@name) AS 'Occupied Length' ,
LEN(@name) AS 'Name Length'
Result : Name Occupied Length Length
Rizwan 6(6*1 byte=6bytes) 6
About the NVARCHAR data:
- It is a variable that has length data type.
- It is use to store Unicode characters.
- It Occupy 2 bytes of space for each character.
example :
DECLARE @name NVARCHAR(20)
SET @name = 'Rizwan'
SELECT @name AS 'Name', DATALENGTH(@name) AS 'Occupied Length' ,
LEN(@name) AS 'Name Length'
Result : Name Occupied Length Length
Rizwan 12(6*2 byte=12 bytes) 6
Conclusion
This tiny article is just to make you aware of the basic differences between the VARCHAR and NVARCHAR data types they are used to store characters, numbers or special characters.
This is my first article
I hope you all will like and that will be helpful to you most of developers confuse about varchar ,nvarchar when we should use varchar,nvarchar.
Please Leave your comments about your opinion good or bad.
Sharing is caring :)
Top comments (1)
Comment if you think it is useful post