What is the difference between varchar and nvarchar?

后端 未结 19 2121
野的像风
野的像风 2020-11-22 04:05

Is it just that nvarchar supports multibyte characters? If that is the case, is there really any point, other than storage concerns, to using varchars

相关标签:
19条回答
  • 2020-11-22 04:27

    The main difference between Varchar(n) and nvarchar(n) is:

    Varchar( Variable-length, non-Unicode character data) size is upto 8000. 1.It is a variable length data type

    1. Used to store non-Unicode characters

    2. Occupies 1 byte of space for each character

    Nvarchar:Variable-length Unicode character data.

    1.It is a variable-length data type

    2.Used to store Unicode characters.

    1. Data is stored in a Unicode encoding. Every language is supported. (for example the languages Arabic, German,Hindi,etc and so on)
    0 讨论(0)
  • 2020-11-22 04:29

    Follow Difference Between Sql Server VARCHAR and NVARCHAR Data Type. Here you could see in a very descriptive way.

    In generalnvarchar stores data as Unicode, so, if you're going to store multilingual data (more than one language) in a data column you need the N variant.

    0 讨论(0)
  • 2020-11-22 04:31

    nvarchar is safe to use compared to varchar in order to make our code error free (type mismatching) because nvarchar allows unicode characters also. When we use where condition in SQL Server query and if we are using = operator, it will throw error some times. Probable reason for this is our mapping column will be difined in varchar. If we defined it in nvarchar this problem my not happen. Still we stick to varchar and avoid this issue we better use LIKE key word rather than =.

    0 讨论(0)
  • 2020-11-22 04:33

    You're right. nvarchar stores Unicode data while varchar stores single-byte character data. Other than storage differences (nvarchar requires twice the storage space as varchar), which you already mentioned, the main reason for preferring nvarchar over varchar would be internationalization (i.e. storing strings in other languages).

    0 讨论(0)
  • 2020-11-22 04:34

    I always use nvarchar as it allows whatever I'm building to withstand pretty much any data I throw at it. My CMS system does Chinese by accident, because I used nvarchar. These days, any new applications shouldn't really be concerned with the amount of space required.

    0 讨论(0)
  • 2020-11-22 04:34

    nvarchar stores data as Unicode, so, if you're going to store multilingual data (more than one language) in a data column you need the N variant.

    0 讨论(0)
提交回复
热议问题