Char type: 1 bytes for English (ASCII) characters, 2 bytes for one kanji, char for storing fixed-length data, high index efficiency on char fields, such as defining char (10), so whether you're storing data that reaches 10 bytes, Takes up 10 bytes of space. Because it is a fixed length, so the speed is high efficiency.
Varchar type: Varchar type is not filled with spaces, such as Varchar (100), but its value is only "Qian", then its value is "Qian"
Char is not the same, such as char (100), its value is "Qian", and in fact it is "Qian" in the database (Qian after a total of 96 spaces, is to fill it up to 100 bytes).
Because char is fixed in length, it will be much faster than varchar! But the program to deal with a bit of trouble, to use the function such as trim to remove both sides of the space!
VARCHAR store variable length data, but storage efficiency is not high char. If the possible value of a field is an unfixed length, we only know that it cannot exceed 10 characters, and it is most cost-effective to define it as VARCHAR (10). The actual length of the varchar type is the actual length of its value +1. Why "+1"? This byte is used to save how much length is actually used.
What is the nchar type and the nvarchar type? In order to convert to a variety of other characters, such as Chinese, phonetic symbols, and so on, each English (ASCII) character occupies 2 bytes, also occupies two bytes for a Chinese character, all characters occupy 2 bytes.
For example
VARCHAR (n): variable-length character data type, stored for a maximum length of 8,000 characters.
As an example:
Insert a select ' wooden son a '
---storage length is 5 bytes and the remaining 3 bytes are freed
Insert a select ' Wood god Easy '
----Storage length is 6 bytes and the remaining 2 bytes are freed
---mean the varchar variable length character data type is consistent with the actual length of the stored data
nvarchar (n): variable-length Unicode data with a maximum length of 4,000 characters.
The storage size of the byte is twice times the number of characters entered,
That means it's double-byte to store the data.
If a single byte is stored in the data, it also occupies storage space in two bytes.
VarChar is generally applicable in English and numerals, nvarchar is suitable for Chinese and other characters, where n represents Unicode constants, can solve the problem of conversion between multiple language character sets