Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  102 Posts | 1 Stories | 317 Comments | 66 Trackbacks

News



Archives

ASP.NET Ventures

First of all, the basic difference between a varchar and a nvarchar datatype is that for each variable the latter one takes double the space needed by the former one. Now why double? Because of the extra "n", which means that it *can* store Unicode characters as well.

Unicode characters represent a wide variety of foreign locales and many times they need an extra byte for the same char storage. Hence nvarchar can store an extended character set.

In SQL Server 2000, varchar has the maximum limit of 8000 characters (when you need to give a particular size), and nvarchar has 4000 characters only (remember it needs double the space needed by a varchar, hence the storage capacity becomes half). Infact a given row in a SQL Server 2000 table cannot exceed 8000 characters in size.

But if you need to store more than 8000 characters? There was no option other than to use TEXT or the NTEXT datattypes, common called as BLOBS (Binary Large Objects), both of which have their own limitations.

Hence in SQL Server 2005, the MAX identifier was introduced, which allows us to go beyond 8000 characters and store upto 2^31- 1 bytes,which comes around 2 GB!! But note that you still cannnot specify a size greater than 8000 characters in n/varchar (like  varchar(12000) is still not allowed, need to use MAX for data greater than 8000 bytes).

We can use them as: varchar (MAX)    nvarchar (MAX)

So as a general practice, avoid using TEXT/NTEXT datattypes and use varchar(MAX) and nvarchar(MAX) instead.

posted on Friday, May 04, 2007 4:33 AM

Feedback

# re: Few Points on VarChar and NVarchar in SQL Server 5/4/2007 6:53 AM Tim Hibbard
Great explaination. Thanks!

# re: Few Points on VarChar and NVarchar in SQL Server 10/30/2007 12:36 PM Ashutosh kumar Jha
well, but i want to know about the difference between char, varchar, nvarchar with wxample.

# re: Few Points on VarChar and NVarchar in SQL Server 3/15/2008 1:05 PM ajeez
Very Nice

# re: Few Points on VarChar and NVarchar in SQL Server 4/3/2008 1:58 AM shuaib
nice, but when storing urdu data it displays ??????????
instead of actual data

# re: Few Points on VarChar and NVarchar in SQL Server 4/3/2008 1:58 AM shuaib
ok, but when storing urdu data it displays ??????????
instead of actual data

# re: Few Points on VarChar and NVarchar in SQL Server 4/3/2008 4:23 PM Swarndeep
Make sure that you declare nvarchar variable for storing URDU characters and see the results in text output window (rather than grid)

# re: Few Points on VarChar and NVarchar in SQL Server 5/26/2008 3:04 PM ukuyu
jkjhkj

# re: Few Points on VarChar and NVarchar in SQL Server 6/27/2008 4:03 PM Atanu Kole
Its not great..........

# re: Few Points on VarChar and NVarchar in SQL Server 8/11/2008 5:18 PM Kathiresan
I've read the above article that's nice and what if we use SQL server 2000 and if we want to use the max length of characters? probably we can't use max identifier in 2000? so just let me know the details. Thanks

# Few Points on VarChar and NVarchar in SQL Server 9/9/2008 7:48 PM Jatin Kaka
Thanks for sharing this..

Crazyrahul84

# Few Points on VarChar and NVarchar in SQL Server 9/9/2008 7:50 PM Aakash
I never knew that !!!

Aakash
|Programmer| http://www.iexplorehere.com |

# re: Few Points on VarChar and NVarchar in SQL Server 9/19/2008 4:20 PM priyesh
i want to use more than 8000 bytes in nvarchar, wat shud i follow pls give a example also.

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 8 and 7 and type the answer here: