Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Difference between char varchar and nvarchar in sql server

Jul 22, 2012
Introduction:

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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

32 comments :

Anonymous said...

Great Article boss....

Anonymous said...

but sir i can not understanding it allows you to store multiple languages in database.. what means.

George Gallegos said...

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.

alfonsomcclure said...

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.

tanvir said...

VERY MUCH CLEAR

Anonymous said...

ggod article

ANIL KUMAR REDDY said...

what you mean of 'allows you to store multiple languages in database'
Can you give the Clear explanation.

Anonymous said...

varchar allocates memory dynamically?
in Oracle we Can use Varchar2

Unknown said...

very very clear explaination

Anonymous said...

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..

Anonymous said...

This website useful for who learn sql r .net.Thanx

William Moore said...

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.

Software Development Company India said...

Really awesome explanation regarding SQL server. Would you please do this for MySQL as well?

Anonymous said...

keep it up brother....really very very simple explanation...tkcr

Unknown said...

yup seriously..
what do u mean by multiple languages in db.. is this for english , gujarati and all that type of thing?

Eone James said...

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.

Anonymous said...

nice article

imran said...

best explanation...

Unknown said...

Nice One

Veersh Dachepally said...

Good Article.....

Unknown said...

wat is unicode???

Anonymous said...

Nice but not clear nvarchar.......

Anonymous said...

enough to move forward

Anonymous said...

very good explanation...........

Unknown said...

Great explanation sir....Thanks specially for depicting the clear picture between varchar & nvarchar .

Anonymous said...

gud one.. everything clearly described

Unknown said...

simply defined and easily understandable nice.......

Anonymous said...

You can insert any language like Hindi, Urdu or Chinese. But varchar doesn't allow to store those characters

Paul Leuben said...

A very nice and detailed explanation , and easily understandable.

Anonymous said...

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. :)

Hii said...

I think varchar is enough...why these two more char,nvarchar,,pls explain

Anonymous said...

Good job

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.