web123456

Difference between nvarchar and varchar

Welcome to follow the official account: Tiantianshuo Programming   Free resume modification, information sharing, and interview experience sharing. Just send a private message.

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. The length setting of nvarchar must be between 1 and 4000. The length setting of varchar must be between 1 and 8000.

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

the difference:

① In terms of storage method, nvarchar is stored by characters, and varchar is stored by bytes.

② From the perspective of storage volume, varchar is relatively space-saving because the storage size is the actual length of bytes, while nvarchar isDouble byte storage

③ In terms of use, if the stored content is English characters without Chinese characters or other languages, it is recommended to use varchar. If you contain Chinese characters, use nvarchar, because the Unicode encoding used by nvarchar will reduce the chance of garbled code appearing.

Summarize:

The size of storage space for today's devices is no longer restricted. Whether it is the scope of the language or the scope of the storage space, nvarchar has a great advantage.

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

Welcome to follow the official account: Tiantianshuo Programming   Free resume modification, information sharing, and interview experience sharing. Just send a private message.