<p>I'm working on a database for a small web app at my school using <code>SQL Server 2005</code>.<br>
I see a couple of schools of thought on the issue of <code>varchar</code> vs <code>nvarchar</code>:</p>

<ol>
<li>Use <code>varchar</code> unless you deal with a lot of internationalized data, then use <code>nvarchar</code>.</li>
<li>Just use <code>nvarchar</code> for everything.</li>
</ol>

<p>I'm beginning to see the merits of view 2.  I know that nvarchar does take up twice as much space, but that isn't necessarily a huge deal since this is only going to store data for a few hundred students.  To me it seems like it would be easiest not to worry about it and just allow everything to use nvarchar.  Or is there something I'm missing?</p>

[{'answer_id': 35369, 'author': 'Joe Barone', 'author_id': 3452, 'author_profile': 'https://Stackoverflow.com/users/3452', 'pm_score': 8, 'selected': True, 'text': "<p>Always use nvarchar. </p>\n\n<p>You may never need the double-byte characters for most applications.  However, if you need to support double-byte languages and you only have single-byte support in your database schema it's really expensive to go back and modify throughout your application.  </p>\n\n<p>The cost of migrating one application from varchar to nvarchar will be much more than the little bit of extra disk space you'll use in most applications.</p>\n"}, {'answer_id': 35374, 'author': 'tbreffni', 'author_id': 637, 'author_profile': 'https://Stackoverflow.com/users/637', 'pm_score': 4, 'selected': False, 'text': '<p>Since your application is small, there is essentially no appreciable cost increase to using nvarchar over varchar, and you save yourself potential headaches down the road if you have a need to store unicode data.</p>\n'}, {'answer_id': 198753, 'author': 'gbn', 'author_id': 27535, 'author_profile': 'https://Stackoverflow.com/users/27535', 'pm_score': 8, 'selected': False, 'text': '<p>Disk space is not the issue... but memory and performance will be.\nDouble the page reads, double index size, strange LIKE and = constant behaviour etc</p>\n\n<p>Do you need to store Chinese etc script? Yes or no...</p>\n\n<p>And from MS BOL "<a href="http://msdn.microsoft.com/en-us/library/ms189617.aspx" rel="noreferrer">Storage and Performance Effects of Unicode</a>" </p>\n\n<p><strong>Edit</strong>:</p>\n\n<p>Recent SO question highlighting how bad nvarchar performance can be...</p>\n\n<p><a href="https://stackoverflow.com/questions/4717520/sql-server-uses-high-cpu-when-searching-inside-nvarchar-strings">SQL Server uses high CPU when searching inside nvarchar strings</a></p>\n'}, {'answer_id': 254119, 'author': 'Thomas Harlan', 'author_id': 33144, 'author_profile': 'https://Stackoverflow.com/users/33144', 'pm_score': 6, 'selected': False, 'text': '<p>Be consistent! JOIN-ing a VARCHAR to NVARCHAR has a big performance hit.</p>\n'}, {'answer_id': 254137, 'author': 'Cade Roux', 'author_id': 18255, 'author_profile': 'https://Stackoverflow.com/users/18255', 'pm_score': 6, 'selected': False, 'text': '<p>nvarchar is going to have significant overhead in memory, storage, working set and indexing, so if the specs dictate that it really will <strong>never</strong> be necessary, don\'t bother.</p>\n\n<p>I would not have a hard and fast "always nvarchar" rule because it can be a complete waste in many situations - particularly ETL from ASCII/EBCDIC or identifiers and code columns which are often keys and foreign keys.</p>\n\n<p>On the other hand, there are plenty of cases of columns, where I would be sure to ask this question early and if I didn\'t get a hard and fast answer immediately, I would make the column nvarchar.</p>\n'}, {'answer_id': 344582, 'author': 'K Richard', 'author_id': 16771, 'author_profile': 'https://Stackoverflow.com/users/16771', 'pm_score': 2, 'selected': False, 'text': "<p>I deal with this question at work often:</p>\n\n<ul>\n<li><p>FTP feeds of inventory and pricing - Item descriptions and other text were in nvarchar when varchar worked fine. Converting these to varchar reduced file size almost in half and really helped with uploads.</p></li>\n<li><p>The above scenario worked fine until someone put a special character in the item description (maybe trademark, can't remember)</p></li>\n</ul>\n\n<p>I still do not use nvarchar every time over varchar. If there is any doubt or potential for special characters, I use nvarchar. I find I use varchar mostly when I am in 100% control of what is populating the field.</p>\n"}, {'answer_id': 494092, 'author': 'WebMasterP', 'author_id': 60445, 'author_profile': 'https://Stackoverflow.com/users/60445', 'pm_score': 5, 'selected': False, 'text': '<p>For your application, nvarchar is fine because the database size is small.  Saying "always use nvarchar" is a vast oversimplification.  If you\'re not required to store things like Kanji or other crazy characters, use VARCHAR, it\'ll use a lot less space.  My predecessor at my current job designed something using NVARCHAR when it wasn\'t needed.  We recently switched it to VARCHAR and saved 15 GB on just that table (it was highly written to).  Furthermore, if you then have an index on that table and you want to include that column or make a composite index, you\'ve just made your index file size larger.</p>\n\n<p>Just be thoughtful in your decision; in SQL development and data definitions there seems to rarely be a "default answer" (other than avoid cursors at all costs, of course).</p>\n'}, {'answer_id': 494167, 'author': 'devstuff', 'author_id': 41321, 'author_profile': 'https://Stackoverflow.com/users/41321', 'pm_score': 3, 'selected': False, 'text': "<p>For that last few years all of our projects have used NVARCHAR for everything, since all of these projects are multilingual. Imported data from external sources (e.g. an ASCII file, etc.) is up-converted to Unicode before being inserted into the database.</p>\n\n<p>I've yet to encounter any performance-related issues from the larger indexes, etc. The indexes do use more memory, but memory is cheap.</p>\n\n<p>Whether you use stored procedures or construct SQL on the fly ensure that all string constants are prefixed with N (e.g. SET @foo = N'Hello world.';) so the constant is also Unicode. This avoids any string type conversion at runtime.</p>\n\n<p>YMMV.</p>\n"}, {'answer_id': 1877846, 'author': 'Tevya', 'author_id': 228421, 'author_profile': 'https://Stackoverflow.com/users/228421', 'pm_score': 2, 'selected': False, 'text': '<p>Why, in all this discussion, has there been no mention of UTF-8?   Being able to store the full unicode span of characters does not mean one has to always allocate two-bytes-per-character (or "code point" to use the UNICODE term).  All of ASCII is UTF-8.   Does SQL Server check for VARCHAR() fields that the text is strict ASCII (i.e. top byte bit zero)?  I would hope not.</p>\n\n<p>If then you want to store unicode <em>and</em> want compatibility with older ASCII-only applications,  I would think using VARCHAR() and UTF-8 would be the magic bullet:  It only uses more space when it needs to.</p>\n\n<p>For those of you unfamiliar with UTF-8, might I recommend <a href="http://en.wikipedia.org/wiki/UTF-8#Advantages_and_disadvantages" rel="nofollow noreferrer">a primer</a>.</p>\n'}, {'answer_id': 5538424, 'author': 'J.A', 'author_id': 691070, 'author_profile': 'https://Stackoverflow.com/users/691070', 'pm_score': 3, 'selected': False, 'text': "<p>I can speak from experience on this, beware of <code>nvarchar</code>.  Unless you absolutely require it this data field type destroys performance on larger database.  I inherited a database that was hurting in terms of performance and space.  We were able to reduce a 30GB database in size by 70%! There were some other modifications made to help with performance but I'm sure the <code>varchar</code>'s helped out significantly with that as well.  If your database has the potential for growing tables to a million + records stay away from <code>nvarchar</code> at all costs.  </p>\n"}, {'answer_id': 15019201, 'author': 'Kjetil Klaussen', 'author_id': 15599, 'author_profile': 'https://Stackoverflow.com/users/15599', 'pm_score': 3, 'selected': False, 'text': "<p>Generally speaking; Start out with the most expensive datatype that has the least constraints. <strong>Put it in production</strong>. If performance starts to be an issue, find out what's actually being stored in those <code>nvarchar</code> columns. Is there any characters in there that wouldn't fit into <code>varchar</code>? If not, switch to varchar. Don't try to pre-optimize before you know where the pain is. My guess is that <strong>the choice between nvarchar/varchar is not what's going to slow down your application</strong> in the foreseable future. There will be other parts of the application where performance tuning will give you much more <em>bang for the bucks</em>.</p>\n"}, {'answer_id': 32389926, 'author': 'Chris Halcrow', 'author_id': 1549918, 'author_profile': 'https://Stackoverflow.com/users/1549918', 'pm_score': 2, 'selected': False, 'text': "<p>There'll be exceptional instances when you'll want to deliberately restrict the data type to ensure it <em>doesn't</em> contain characters from a certain set. For example, I had a scenario where I needed to store the domain name in a database. Internationalisation for domain names wasn't reliable at the time so it was better to restrict the input at the base level, and help to avoid any potential issues.</p>\n"}, {'answer_id': 32871477, 'author': 'Solomon Rutzky', 'author_id': 577765, 'author_profile': 'https://Stackoverflow.com/users/577765', 'pm_score': 5, 'selected': False, 'text': '<p>I hesitate to add yet another answer here as there are already quite a few, but a few points need to be made that have either not been made or not been made clearly.</p>\n<p><strong>First:</strong> Do <em>not</em> always use <code>NVARCHAR</code>. That is a very dangerous, and often costly, attitude / approach. And it is no better to say &quot;<em>Never</em> use cursors&quot; since they are sometimes the most efficient means of solving a particular problem, and the common work-around of doing a <code>WHILE</code> loop will almost always be slower than a <em>properly</em> done Cursor.</p>\n<p>The only time you should use the term &quot;always&quot; is when advising to &quot;always do what is best for the situation&quot;. Granted that is often difficult to determine, especially when trying to balance short-term gains in development time (manager: &quot;we need this feature -- that you didn\'t know about until just now -- a week ago!&quot;) with long-term maintenance costs (manager who initially pressured team to complete a 3-month project in a 3-week sprint: &quot;why are we having these performance problems? How could we have possibly done X which has no flexibility? We can\'t afford a sprint or two to fix this. What can we get done in a week so we can get back to our priority items? And we definitely need to spend more time in design so this doesn\'t keep happening!&quot;).</p>\n<p><strong>Second:</strong> @gbn\'s <a href="https://stackoverflow.com/a/198753/577765">answer</a> touches on some very important points to consider when making certain data modeling decisions when the path isn\'t 100% clear. But there is even more to consider:</p>\n<ul>\n<li>size of transaction log files</li>\n<li>time it takes to replicate (if using replication)</li>\n<li>time it takes to ETL (if ETLing)</li>\n<li>time it takes to ship logs to a remote system and restore (if using Log Shipping)</li>\n<li>size of backups</li>\n<li>length of time it takes to complete the backup</li>\n<li>length of time it takes to do a restore (this might be important some day ;-)</li>\n<li>size needed for tempdb</li>\n<li>performance of triggers (for inserted and deleted tables that are stored in tempdb)</li>\n<li>performance of row versioning (if using SNAPSHOT ISOLATION, since the version store is in tempdb)</li>\n<li>ability to get new disk space when the CFO says that they just spent $1 million on a SAN last year and so they will not authorize another $250k for additional storage</li>\n<li>length of time it takes to do INSERT and UPDATE operations</li>\n<li>length of time it takes to do index maintenance</li>\n<li>etc, etc, etc.</li>\n</ul>\n<p>Wasting space has a <strong>huge</strong> cascade effect on the entire system. I wrote an article going into explicit detail on this topic: <a href="https://www.sqlservercentral.com/articles/disk-is-cheap-orly-4" rel="nofollow noreferrer">Disk Is Cheap! ORLY?</a> (free registration required; sorry I don\'t control that policy).</p>\n<p><strong>Third:</strong> While some answers are incorrectly focusing on the &quot;this is a small app&quot; aspect, and some are correctly suggesting to &quot;use what is appropriate&quot;, none of the answers have provided real guidance to the O.P. An important detail mentioned in the Question is that this is a web page for their school. Great! So we can suggest that:</p>\n<ul>\n<li>Fields for Student and/or Faculty names should <em>probably</em> be <code>NVARCHAR</code> since, over time, it is only getting more likely that names from other cultures will be showing up in those places.</li>\n<li>But for street address and city names? The purpose of the app was not stated (it would have been helpful) but assuming the address records, if any, pertain to just to a particular geographical region (i.e. a single language / culture), then use <code>VARCHAR</code> with the appropriate Code Page (which is determined from the Collation of the field).</li>\n<li>If storing State and/or Country ISO codes (no need to store <code>INT</code> / <code>TINYINT</code> since ISO codes are fixed length, human readable, and well, standard :) use <code>CHAR(2)</code> for two letter codes and <code>CHAR(3)</code> if using 3 letter codes. And consider using a binary Collation such as <code>Latin1_General_100_BIN2</code>.</li>\n<li>If storing postal codes (i.e. zip codes), use <code>VARCHAR</code> since it is an international standard to never use any letter outside of A-Z. And yes, still use <code>VARCHAR</code> even if only storing US zip codes and not INT since zip codes are not numbers, they are strings, and some of them have a leading &quot;0&quot;. And consider using a binary Collation such as <code>Latin1_General_100_BIN2</code>.</li>\n<li>If storing email addresses and/or URLs, use <code>NVARCHAR</code> since both of those can now contain Unicode characters.</li>\n<li>and so on....</li>\n</ul>\n<p><strong>Fourth:</strong> Now that you have <code>NVARCHAR</code> data taking up twice as much space than it needs to for data that fits nicely into <code>VARCHAR</code> (&quot;fits nicely&quot; = doesn\'t turn into &quot;?&quot;) and somehow, as if by magic, the application did grow and now there are millions of records in at least one of these fields where <em>most</em> rows are standard ASCII but some contain Unicode characters so you have to keep <code>NVARCHAR</code>, consider the following:</p>\n<ol>\n<li><p>If you are using SQL Server 2008 - 2016 RTM <em>and</em> are on Enterprise Edition, OR if using SQL Server 2016 SP1 (which made Data Compression available in all editions) or newer, then you can enable <a href="https://learn.microsoft.com/en-us/sql/relational-databases/data-compression/data-compression" rel="nofollow noreferrer">Data Compression</a>. Data Compression can (but won\'t &quot;always&quot;) compress Unicode data in <code>NCHAR</code> and <code>NVARCHAR</code> fields. The determining factors are:</p>\n</li>\n<li><p><code>NCHAR(1 - 4000)</code> and <code>NVARCHAR(1 - 4000)</code> use the <a href="http://unicode.org/reports/tr6/" rel="nofollow noreferrer">Standard Compression Scheme for Unicode</a>, but only starting in SQL Server 2008 R2, AND only for IN ROW data, not OVERFLOW! This appears to be better than the regular ROW / PAGE compression algorithm.</p>\n</li>\n<li><p><code>NVARCHAR(MAX)</code> and <code>XML</code> (and I guess also <code>VARBINARY(MAX)</code>, <code>TEXT</code>, and <code>NTEXT</code>) data that is IN ROW (not off row in LOB or OVERFLOW pages) can at least be PAGE compressed, but <em>not</em> ROW compressed. Of course, PAGE compression depends on size of the in-row value: I tested with VARCHAR(MAX) and saw that 6000 character/byte rows would not compress, but 4000 character/byte rows did.</p>\n</li>\n<li><p>Any OFF ROW data, LOB or OVERLOW = No Compression For You!</p>\n</li>\n<li><p>If using SQL Server 2005, or 2008 - 2016 RTM and <em>not</em> on Enterprise Edition, you can have two fields: one <code>VARCHAR</code> and one <code>NVARCHAR</code>. For example, let\'s say you are storing URLs which are mostly all base ASCII characters (values 0 - 127) and hence fit into <code>VARCHAR</code>, but sometimes have Unicode characters. Your schema can include the following 3 fields:</p>\n <pre class="lang-sql prettyprint-override"><code>   ...\n   URLa VARCHAR(2048) NULL,\n   URLu NVARCHAR(2048) NULL,\n   URL AS (ISNULL(CONVERT(NVARCHAR([URLa])), [URLu])),\n   CONSTRAINT [CK_TableName_OneUrlMax] CHECK (\n                     ([URLa] IS NOT NULL OR [URLu] IS NOT NULL)\n                 AND ([URLa] IS NULL OR [URLu] IS NULL))\n );\n</code></pre>\n<p>In this model you <em>only</em> SELECT from the <code>[URL]</code> computed column. For inserting and updating, you determine which field to use by seeing if converting alters the incoming value, which has to be of <code>NVARCHAR</code> type:</p>\n <pre class="lang-sql prettyprint-override"><code> INSERT INTO TableName (..., URLa, URLu)\n VALUES (...,\n         IIF (CONVERT(VARCHAR(2048), @URL) = @URL, @URL, NULL),\n         IIF (CONVERT(VARCHAR(2048), @URL) &lt;&gt; @URL, NULL, @URL)\n        );\n</code></pre>\n</li>\n<li><p>You can GZIP incoming values into <code>VARBINARY(MAX)</code> and then unzip on the way out:</p>\n<ul>\n<li>For SQL Server 2005 - 2014: you can use SQLCLR. <a href="https://SQLsharp.com/?ref=so_32871477" rel="nofollow noreferrer">SQL#</a> (a SQLCLR library that I wrote) comes with <strong>Util_GZip</strong> and <strong>Util_GUnzip</strong> in the Free version</li>\n<li>For SQL Server 2016 and newer: you can use the built-in <code>COMPRESS</code> and <code>DECOMPRESS</code> functions, which are also GZip.</li>\n</ul>\n</li>\n<li><p>If using SQL Server 2017 or newer, you can look into making the table a Clustered Columnstore Index.</p>\n</li>\n<li><p>While this is not a viable option yet, SQL Server 2019 introduces native support for UTF-8 in <code>VARCHAR</code> / <code>CHAR</code> datatypes. There are currently too many bugs with it for it to be used, but if they are fixed, then this is an option for <em>some</em> scenarios. Please see my post, &quot;<a href="https://sqlquantumleap.com/2018/09/28/native-utf-8-support-in-sql-server-2019-savior-false-prophet-or-both/" rel="nofollow noreferrer">Native UTF-8 Support in SQL Server 2019: Savior or False Prophet?</a>&quot;, for a detailed analysis of this new feature.</p>\n</li>\n</ol>\n'}, {'answer_id': 43376826, 'author': 'ajeh', 'author_id': 2721750, 'author_profile': 'https://Stackoverflow.com/users/2721750', 'pm_score': 1, 'selected': False, 'text': '<p>If you are using <code>NVARCHAR</code> just because a system stored procedure requires it, the most frequent occurrence being inexplicably <code>sp_executesql</code>, and your dynamic SQL is very long, you would be better off from performance perspective doing all string manipulations (concatenation, replacement etc.) in <code>VARCHAR</code> then converting the end result to <code>NVARCHAR</code> and feeding it into the proc parameter. So no, do not always use <code>NVARCHAR</code>!</p>\n'}]
['https://Stackoverflow.com/questions/35366', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2147/']