nVarChar vs VarChar

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
I'm trying to decide if there's any real advantage to using varchar anymore. With diskspace being pretty cheap, and user/app/language support being a real issue, is there any real reason to use varchar? I know it takes up less space than nVarChar, but you lose unicode support and run the risk of some users (maybe in different countries) being able to input data outside the scope of what varchar accepts.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Your users should be isolated from your database anyways so them giving invalid input to your database should not pose a problem, they should get an error message from your app.

When you create a database, table, or column you can specify a character set and collation rules. That is what determines what values can be stored. Using a nvarchar('national varchar' in mysql) just informs the DB engine to use a specific defaulted character set. If that character set works then use it, otherwise you need to specify one that works for you. It just so happens that in mysql 'national' == UTF8. CREATE TABLE blah(field varchar(255) CHARACTER SET utf8); is the same as using nvarchar.

Honestly though, if you're writing a web application and only accept ASCII encoded input you're doing it wrong.
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
Your users should be isolated from your database anyways so them giving invalid input to your database should not pose a problem, they should get an error message from your app.

When you create a database, table, or column you can specify a character set and collation rules. That is what determines what values can be stored. Using a nvarchar('national varchar' in mysql) just informs the DB engine to use a specific defaulted character set. If that character set works then use it, otherwise you need to specify one that works for you. It just so happens that in mysql 'national' == UTF8. CREATE TABLE blah(field varchar(255) CHARACTER SET utf8); is the same as using nvarchar.

Honestly though, if you're writing a web application and only accept ASCII encoded input you're doing it wrong.

That's kind of what I think.. By limiting text input to varchar for an app that could be hit from anywhere on the globe is basically limiting the functionality and looking for problems. Everything I'm reading is that if you have a remote chance of international users and aren't hard up for disk space, the smart thing to do would be to use nVarChar.
 

ForumMaster

Diamond Member
Feb 24, 2005
7,792
1
0
That's kind of what I think.. By limiting text input to varchar for an app that could be hit from anywhere on the globe is basically limiting the functionality and looking for problems. Everything I'm reading is that if you have a remote chance of international users and aren't hard up for disk space, the smart thing to do would be to use nVarChar.

I might not necessarily use nvarchar in every case. it depends on the dbms. for example, in oracle (you'll have to excuse me, I'm an oracle dba) there both a database character set, and a national character set.
if default settings are not changed, the national character set is atlutf16. (this encompasses just about every possible character that exists)
however, the standard varchar/clob columns will derive their encoding from the database character set.
for 99% of the cases, atlutf8 will suffice and then in all sense their is no difference except one critical one:
utf16 is a four byte encoding. that means that for all sense, you'll only be able to insert 1000 Unicode characters. utf8 will allow 2000.

thus, there is a difference beyond just "aww fuck it! storage is cheap".
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
I might not necessarily use nvarchar in every case. it depends on the dbms. for example, in oracle (you'll have to excuse me, I'm an oracle dba) there both a database character set, and a national character set.
if default settings are not changed, the national character set is atlutf16. (this encompasses just about every possible character that exists)
however, the standard varchar/clob columns will derive their encoding from the database character set.
for 99% of the cases, atlutf8 will suffice and then in all sense their is no difference except one critical one:
utf16 is a four byte encoding. that means that for all sense, you'll only be able to insert 1000 Unicode characters. utf8 will allow 2000.

thus, there is a difference beyond just "aww fuck it! storage is cheap".

I cringe every time I see a mysql database with 'latin1_swidesh_ci' as the character set. D:
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I only use varchar for internal stuff that I know is not going to need wide characters, and even that use is becoming pretty uncommon. For anything that is input by or returned to the user I utilize nvarchar.
 

ForumMaster

Diamond Member
Feb 24, 2005
7,792
1
0
I cringe every time I see a mysql database with 'latin1_swidesh_ci' as the character set. D:

i agree 100%. for 99.9% of our oracle database, the database character set is atl32utf8. i don't care whether or not it might actually need it.

the problem usually arises when upgrading databases with different character sets. that's...let fun.
in utf8, ascii character only take one byte, but the important thing is knowing the limitations of the character set you're choosing, and what the outcomes are.
 

clamum

Lifer
Feb 13, 2003
26,252
403
126
I only use varchar for internal stuff that I know is not going to need wide characters, and even that use is becoming pretty uncommon. For anything that is input by or returned to the user I utilize nvarchar.
Seconded.
 

patticrook33

Junior Member
May 23, 2012
8
0
0
As far as I know Nvarchar is UTF-16 and Varchar is UTF-8. It meaning Nvarchar support some special language like Chinese or Vietnamese. Is it right?
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |