Converting Varchar to NVarchar?

Curt picture Curt · Oct 20, 2011 · Viewed 25.8k times · Source

I know when converting from nvarchar to varchar, some data will be lost/changed.

However, are there any risks of data changing when converting a varchar data type to an nvarchar?

Answer

musefan picture musefan · Oct 20, 2011

nvarchar stores unicode characters which are twice the size of varchar characters. So as long as your nvarchar is atleast twice the length of your vchar this will not be a problem.

Converting the other way could still be achieved providing you have not used any characters outside the ASCII character range (i.e. you do not have Unicode characters)

In short, make sure your nvarchar lengths are twice the size of your largest varchar value and then make the change.


As I seem to have received a couple of downvotes on this (with no explanation), I want to make it clear that when I refer to length above I mean the size, e.g. that amount of storage data required. Please note my comment below, which I will also include here:

If you are talking about changing the length with SQL then I think you should be ok to have the same length. This is because when you specify the length you do so based on the number of characters and not the actually amount of data that gets stored