The main difference between VarChar and NVarChar is the supported character set: VarChar only supports ASCII or Latin1 character set, while NVarChar supports Unicode character set, which means that NVarChar can store more kinds of characters, including Chinese characters, Japanese characters etc.
The difference between VarChar and NVarChar in MySQL
VarChar and NVarChar are variable-length strings stored in MySQL of two data types. Their main difference is that NVarChar supports Unicode characters, while VarChar does not.
Main differences
Features |
VarChar |
NVarChar |
Character set |
ASCII or Latin1 |
Unicode |
Storage space |
Storage by bytes |
Storage by characters |
Maximum length |
65,535 bytes |
4,000 characters |
Efficiency |
More efficient |
Low efficiency for storing non-Unicode strings |
Compatibility |
Compatible with old apps |
Compatible with modern apps |
Detailed description
- Character set: VarChar stores strings in ASCII or Latin1 character set, which limits it to only store English letters, numbers and some special symbols. NVarChar stores strings in the Unicode character set and supports multiple languages and characters, including Chinese characters, Japanese characters, etc.
-
Storage space: VarChar stores strings in bytes, while NVarChar stores strings in characters. For storing non-Unicode strings, VarChar is more efficient because one byte can represent one character. For storing Unicode strings, NVarChar is more efficient because it can combine multiple bytes into a single character.
-
Maximum length: The maximum length of VarChar is 65,535 bytes, while the maximum length of NVarChar is 4,000 characters. NVarChar has advantages when storing large text data.
-
Efficiency: VarChar is more efficient for storing non-Unicode strings because it does not require Unicode conversion. For storing Unicode strings, NVarChar is more efficient because it can take advantage of the Unicode character set.
-
Compatibility: VarChar is compatible with older applications, as most older applications use ASCII or Latin1 character sets. And NVarChar is compatible with modern applications because it supports the Unicode character set.
The above is the detailed content of The difference between varchar and nvarchar in mysql. For more information, please follow other related articles on the PHP Chinese website!