The difference between nvarchar and varchar

1. Varchar is a non-Unicode variable-length type, and nvarchar is a Unicode variable-length type.

2. The maximum length of varchar and nvarchar is different, and the length of nvarchar must be set between 1 and 4000. The length of varchar must be set between 1 and 8000.

3. The number of bytes that varchar can store is its length. The number of bytes that nvarchar can store is twice its length.

the difference:

  ① From the storage method, nvarchar is stored in characters, and varchar is stored in bytes.

  ② From the perspective of storage capacity, varchar is more space-saving, because the storage size is the actual length of bytes, while nvarchar is double-byte storage .

  ③ In use, if the storage content is English characters but no Chinese characters or other languages, it is recommended to use varchar, and use nvarchar for Chinese characters, because the Unicode encoding and uniform encoding used by nvarchar will reduce the chance of garbled characters.

to sum up:

   With current equipment, the size of the storage space is no longer limited. Regardless of the range of language and the range of storage space, nvarchar has a great advantage.

   It is recommended to choose nvarchar for the database of the project.

Guess you like

Origin blog.csdn.net/Sunshineoe/article/details/111715231