Home  >  Article  >  Database  >  A brief discussion on MySQL drifting (2)

A brief discussion on MySQL drifting (2)

黄舟
黄舟Original
2017-03-08 13:23:041049browse


The difference between nvarchar and varchar
varchar(n)
Variable length of n bytes and non-Unicode character data. n must be a number between 1 and 8,000. The storage size is the actual length in bytes of the input data, not n bytes.
nvarchar(n)
Variable length Unicode character data containing n characters. The value of n must be between 1 and 4,000. The storage size in bytes is twice the number of characters entered.

Case:
Two fields have field values ​​respectively: me and coffee
Then the varchar field occupies 2×2+6=10 bytes of storage space, while the nvarchar field occupies 8×2= 16 bytes of storage space.

If the field value is only in English, you can choose varchar. If the field value contains more double-byte (Chinese, Korean, etc.) characters, use nvarchar

The difference between nvarchar and varchar
varchar(n)
Variable length of n bytes and non-Unicode character data. n must be a number between 1 and 8,000. The storage size is the actual length in bytes of the input data, not n bytes.
nvarchar(n)
Variable length Unicode character data containing n characters. The value of n must be between 1 and 4,000. The storage size in bytes is twice the number of characters entered.

Case:
Two fields have field values ​​respectively: me and coffee
Then the varchar field occupies 2×2+6=10 bytes of storage space, while the nvarchar field occupies 8×2= 16 bytes of storage space.

If the field value is only in English, you can choose varchar. If the field value contains many double-byte (Chinese, Korean, etc.) characters, use nvarchar


The above is the detailed content of A brief discussion on MySQL drifting (2). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]