snippetjournal

– notes, snippet codes, and my journal

BASIC NOTE : VARCHAR and NVARCHAR2

leave a comment »

SQL Server provides both datatypes to store character information. For the most part the two datatypes are identical in how you would work with them within SQL Server or from an application. The difference is that nvarchar is used to store unicode data, which is used to store multilingual data in your database tables.

Other languages have an extended set of character codes that need to be saved and this datatype
allows for this extension. If your database will not be storing multilingual data you should use the varchar datatype instead. The reason for this is that nvarchar takes twice as much space as varchar, this is because of the need to store the extended character codes for other languages.
http://www.geekinterview.com/question_details/34134

The NVARCHAR2
<http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#i45685&gt;

datatype was introduced by Oracle for databases that want to use Unicode for some columns while keeping another character set for the rest of the database (which uses VARCHAR2). The NVARCHAR2 is a Unicode-only datatype.

One reason you want to use NVARHCAR2 might be that your DB uses a non-Unicode character and you still want to be able to store Unicode data for some columns. Another reason might be that you want to use two Unicode character set (AL32UTF8 for data that comes mostly from western Europe, AL16UTF16 for data that comes mostly from Asia for example) because different character sets won’t store the same data equally efficiently.

http://stackoverflow.com/questions/4508351/difference-between-varchar210-char-and-nvarchar210

Both columns in your example (Unicode |VARCHAR2(10 CHAR)| and |NVARCHAR2(10)|) would be able to store the same data, however the byte storage will be different. Some strings may be stored more efficiently in one or the other.

Written by snippetjournal

October 21, 2012 at 2:07 am

Posted in Programming

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: