Introduction:
In this article I will explain what is the difference between char, varchar and nvarchar in SQL Server.
In this article I will explain what is the difference between char, varchar and nvarchar in SQL Server.
Description:
In
previous post I explained many articles relating to SQL
Server.
Now I will explain the differences between char, varchar and nvarchar in SQL
Server. Actually one of blog reader has asked me question regarding
differences between varchar and nvarchar at that time I decided it’s better to
write article on this topic.
Char DataType
Char
datatype which is used to store fixed length of characters. Suppose if we
declared char(50) it will allocates memory for 50 characters. Once we declare
char(50) and insert only 10 characters of word then only 10 characters of
memory will be used and other 40 characters of memory will be wasted.
varchar DataType
Varchar
means variable characters and it is used to store non-unicode characters. It will
allocate the memory based on number characters inserted. Suppose if we declared
varchar(50) it will allocates memory of 0 characters at the time of declaration.
Once we declare varchar(50) and insert only 10 characters of word it will
allocate memory for only 10 characters.
nvarchar DataType
nvarchar
datatype same as varchar datatype
but only difference nvarchar is used
to store Unicode characters and it allows you to store multiple languages in
database. nvarchar datatype will
take twice as much space to store extended set of characters as required by
other languages.
So
if we are not using other languages then it’s better to use varchar datatype instead of nvarchar
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
32 comments :
Great Article boss....
but sir i can not understanding it allows you to store multiple languages in database.. what means.
As such I know this but still some of the doubts to these differences are more cleared now. Really good explanation covering everything to it.
Its as if you read my thoughts! You appear to understand a great deal relating to this, as if you authored it inside it or something like that. I believe you could use a couple of photos they are driving the content home a little, but apart from that, this really is great blog. An excellent read. I'll certainly return.
VERY MUCH CLEAR
ggod article
what you mean of 'allows you to store multiple languages in database'
Can you give the Clear explanation.
varchar allocates memory dynamically?
in Oracle we Can use Varchar2
very very clear explaination
Say if ur migrating ur application to multilingual application in that scenario ur application should support all languages like chines, japnese ...hence in db side u need to chane the table structure in such a way to insert even there lanuage characters too ( as they occupy more space).hence we go for nvarchar datatype for string operations..
This website useful for who learn sql r .net.Thanx
I have read about difference between char varchar and nvarchar in sql server in this article. I think you have well tried to explain through this post. Well Done.
Really awesome explanation regarding SQL server. Would you please do this for MySQL as well?
keep it up brother....really very very simple explanation...tkcr
yup seriously..
what do u mean by multiple languages in db.. is this for english , gujarati and all that type of thing?
As you described difference between char varchar and nvarchar in sql server is really appreciate because this helps to those who are in fresher level.
nice article
best explanation...
Nice One
Good Article.....
wat is unicode???
Nice but not clear nvarchar.......
enough to move forward
very good explanation...........
Great explanation sir....Thanks specially for depicting the clear picture between varchar & nvarchar .
gud one.. everything clearly described
simply defined and easily understandable nice.......
You can insert any language like Hindi, Urdu or Chinese. But varchar doesn't allow to store those characters
A very nice and detailed explanation , and easily understandable.
Actually Varchar is used to store non-unicode characters.and nvarchar store unicode characters, Non-unicode takes 1 byte storage and unicode takes 2 byte storage.
I hope it would help to understand above concept what suresh sir tried to explain. :)
I think varchar is enough...why these two more char,nvarchar,,pls explain
Good job
Note: Only a member of this blog may post a comment.