was successfully added to your cart.

When Do I Use NVarChar vs. VarChar in SQL?

When Do I Use NVarChar vs. VarChar in SQL?

By April 6, 2018 Ask Tim 3 Comments

Using or Omitting the N Really Does Matter

When it comes to storing text data in SQL, there are a couple of main options: varchar and nvarchar. So the question comes up: which one do I use? The answer really depends on how well you can see into the future and use of your column. VarChar is used to store ASCII characters whereas NVarChar stores Unicode characters. That means NVarChar supports characters found outside the standard English alphabet (really important when it comes to supporting an audience of any size even in the US).

The downside of NVarChar, though, is that it uses twice the space of VarChar. This can be an issue in super-large databases where space is at a premium (when your database is so large it takes over 24 hours to do a daily backup, you have a problem). However, even in smaller databases, space can be an issues. Sure, you have disk space for it, but it makes every backup larger (which you sometimes pay for by size) and it makes every restore longer.

So, in conclusion, when in doubt, choose NVarChar because of the support for a wider audience but if you are sure the data is only ASCII-based, VarChar may be a better option in order to save space. If you want to learn more about SQL, check out my course on becoming a SQL Developer.

Join the discussion 3 Comments

Leave a Reply