SQL Server char data types can be confusing if you are not an experience developer. You may also get to ask a question in an interview, what is the difference between char and varchar in SQL Server? SQL Server has char, varchar, nchar, and nvarcar data types that all are used for storing character data. In this article, learn the difference between CHAR, VARCHAR, NCHAR and NVARCHAR data types. Actually it is simple but sometimes people get confused.
To store data as characters, numeric values and special characters in a database, there are 4 data types that can be used. So what is the difference among all 4 of these data types?
- CHAR vs VARCHAR
- NCHAR vs NVARCHAR
Considering an example, we will look into each one of them.
- DECLARE @string CHAR(20)
- SET @string = 'Robin'
- SELECT @string AS 'String', DATALENGTH(@string) AS 'Datalength' , LEN(@string) AS 'Len'
As you know we represent the character values within single quotes, for example 'Robin'. But do you know we can represent these same characters within double quotes similar to programming languages representing a string, for example “Robin”? This can be done by setting the value:
- SET QUOTED_IDENTIFIER OFF
By default, it is set to ON
CHAR vs VARCHAR
Talking about the CHAR data type:
- It is a fixed length data type
- Used to store non-Unicode characters
- Occupiers 1 byte of space for each character
If the value provided to a variable of CHAR data type is shorter than the length of a column of declared the size of the variable, then the value would be right-padded with blanks to match the size of column length.
- DECLARE @string CHAR(20)
- SET @string = 'Robin'
- SELECT @string AS 'String', DATALENGTH(@string) AS 'Datalength' , LEN(@string) AS 'Len'

About the VARCHAR data type:
- It is a variable length data type
- Used to store non-Unicode characters
- Occupies 1 byte of space for each character
- DECLARE @string VARCHAR(20)
- SET @string = 'Robin'
- SELECT @string AS 'String', DATALENGTH(@string) AS 'Datalength' , LEN(@string) AS 'Len'

Note: If SET ANSI_PADDING is OFF when CREATE TABLE or ALTER TABLE is executed, a CHAR column defined as NULL is considered as VARCHAR.
When to use what?
If you are sure about the fixed length of the data that would be captured for any specific column then go for CHAR data type and if the data may vary then go for VARCHAR.
NCHAR vs NVARCHAR
Similar to CHAR data type, the NCHAR data type:
- Is a fixed length data type
- Used to store Unicode characters (for example the languages Arabic, German and so on)
- Occupies 2 bytes of space for each character
- DECLARE @string NCHAR(20)
- SET @string = 'Robin'
- SELECT @string AS 'String', DATALENGTH(@string) AS 'Datalength' , LEN(@string) AS 'Len'
About the NVARCHAR data type:
- It is a variable-length data type
- Used to store Unicode characters
- Occupies 2 bytes of space for each character
- DECLARE @string NVARCHAR(20)
- SET @string = 'Robin'
- SELECT @string AS 'String', DATALENGTH(@string) AS 'Datalength' , LEN(@string) AS 'Len'
When to use what?
If your column will store a fixed-length Unicode characters like French, Arabic and so on characters then go for NCHAR. If the data stored in a column is Unicode and can vary in length, then go for NVARCHAR.
Conclusion
This article explains the differences between CHAR, VARCHAR, NCHAR and NVARCHAR data types. All of these data types are used to store characters, numbers or special characters. I hope you like this small article and will that it will be helpful to you at some point of time. Leave your comments whether its good or bad. Sharing is valuable no matter what :)


Gautam NagrajPosted Jul 26, 2025, 9:51 AM EDT
Very nice explanation with details, Thank you for this post
Radhe GuptaPosted Dec 8, 2021, 4:13 AM EST
Superb article and Nice Explanation . Thanks for this post
Larry CoatesPosted Mar 16, 2020, 6:52 AM EDT
Pradeep, Great article that was straight forward and very clear in the explanation! Many people will find this article to be very helpful. I also loved the "Extras" about the "SET QUOTED_IDENTIFIER OFF" and "SET ANSI_PADDING is OFF" SQL Server keywords... very goo to know info!
MANOJ APPosted Dec 10, 2019, 6:40 PM EST
Thank your for another useful article
rajesh vsPosted Jun 8, 2019, 9:18 PM EDT
Supperb artcicle and Nice Explanation . Thanks for your post
Vishal PrajapatiPosted May 27, 2019, 8:06 PM EDT
Awesome article.. Thanks for sharing.
Jignesh KumarTOP 100Posted May 27, 2019, 7:11 PM EDT
Nice one thanks for sharing
Jayesh AgrawalPosted May 27, 2019, 5:37 PM EDT
Nice article... it would be make it perfect if you can add performance measurements in this article while using char, nchar, varchar, varchar(max), nvarchar.
prabhat kumarPosted May 1, 2019, 2:51 AM EDT
Nice Article ...sir
Ketan ShindePosted Jan 28, 2019, 11:46 PM EST
Good........
Sourav MukherjeePosted Dec 4, 2018, 6:04 PM EST
Nice Article..Pradeep.
Amita GuptaPosted Nov 14, 2018, 12:25 AM EST
Thanx pardeep. its really useful.
Pravin LalgePosted Jul 23, 2018, 11:24 PM EDT
Really good efforts..
Amol KumbhkarnaPosted May 8, 2018, 2:41 AM EDT
You made my day Bro...!!! It is very useful as I face same question in my recent interview..!! Thanks for sharing it.
Tamheed KhanPosted Feb 24, 2018, 4:10 AM EST
Awsum artical Pradeep
Rahul shindePosted Jan 17, 2018, 7:44 AM EST
Nice explaination than u
Hamid KhanPosted Jan 14, 2018, 8:29 PM EST
Great and helpful............
Dennis ThomasPosted Jan 12, 2018, 2:36 AM EST
Nicely explained Pradeep. Thank you!
Insaf MohammadPosted Dec 18, 2017, 7:01 PM EST
Concept cleared now
Sagar PrakashPosted Nov 26, 2017, 3:42 AM EST
Good article..Thank you
Pavan SinghPosted Aug 9, 2017, 9:32 AM EDT
It's really a good share for fresher as well as experienced.
Sivaiah DevaraPosted Mar 27, 2017, 7:07 PM EDT
Very clear explanation, thank u ...
Rahul ParabPosted Mar 24, 2017, 1:39 AM EDT
Awesomeeeeeeeeee explanation. Thanks :)
Nigel FernandesPosted Dec 7, 2016, 6:05 PM EST
Good article, Useful .......
Neeraj PalPosted Oct 18, 2016, 8:30 PM EDT
Excellent ..Easy to learn
Vaibhav DeshmukhPosted Sep 21, 2016, 4:52 AM EDT
Superb... Easy to learn.
SubashPosted Sep 15, 2016, 8:31 PM EDT
Nice share
kalu singh raoPosted Jul 3, 2016, 5:16 AM EDT
Nice...
Vignesh ManiTOP 100Posted Jun 29, 2016, 12:03 AM EDT
Good one
Aniket NarvankarPosted Jun 3, 2016, 3:39 AM EDT
Very useful and nice Article
Roland WalesPosted Jun 5, 2015, 10:57 AM EDT
A warning about using fixed char: if the actual length of the data is ever less than the fixed length of the field, if statements may not work as expected. If Field1 = 'ABC' will not be true if a 4 character field is 'ABC '. You need the trailing space in the if statement. This is a reason why some of us always use varchar.
pankaj kumarPosted Jun 2, 2015, 1:49 AM EDT
Very helpful
Napo VPosted May 27, 2015, 2:01 AM EDT
well explained
Khargesh RajputPosted May 14, 2015, 6:24 PM EDT
Thnx
Nitin PatilPosted May 3, 2015, 6:04 PM EDT
good one..
Subrat PandaPosted Dec 30, 2014, 9:21 PM EST
can varchar supports unicode character???
Abhijit KakadePosted Nov 26, 2014, 1:02 AM EST
Very good explanation pradeep.. its very useful.
Manish Kumar ChoudharyPosted Nov 23, 2014, 9:49 PM EST
nice Pradeep Shet sir..
Cyril JacobPosted Nov 23, 2014, 8:08 PM EST
Very informative & so simple even for a beginner
Niraj SinghPosted Oct 5, 2014, 4:12 AM EDT
thanks sir
Hemant SrivastavaPosted Jul 11, 2014, 11:08 AM EDT
useful information!
Archana KharatPosted Jul 8, 2014, 2:21 AM EDT
nice article sir
Ramdas BhosalePosted Jul 7, 2014, 8:44 PM EDT
Its very useful for beginners.
Pankaj BajajPosted Jul 6, 2014, 11:43 PM EDT
Thanks Pradeep..very well explained in a simple way.
Prerana TiwariPosted Jul 6, 2014, 7:26 PM EDT
Nice article..........
johnson yuanPosted Jul 6, 2014, 9:25 AM EDT
I think you put the wrong image order at the beginning, when DECLARE @string VARCHAR(20), the DATALENGTH should be 5, and ECLARE @string CHAR(20), the DATALENGTH shoule be 20, but you put the wrong order.
Sai SherlekarPosted Jul 6, 2014, 1:49 AM EDT
padeep, what is the difference between varchar(1) and char(1)?
Mahesh ChandTOP 10Posted Jul 6, 2014, 12:00 AM EDT
Very good Pradeep. I like the point "When to use what".
Joginder BangerPosted Jul 5, 2014, 6:30 AM EDT
Good bro....it's very use full ...for any one
Jasminder SinghPosted Jul 4, 2014, 10:15 PM EDT
Good one for the beginners...!!!