Most of the time, when we create a database, we select varchar or nvarchar when setting the data type for the field. Of course, you can also select another data type. This article only describes the varchar and nvarchar types. Test Table Structure:
Here, I enter a value for each field, as shown in:
It can be summarized as follows:
Varchar typeIn bytes, its varchar (20) indicates that only 20 bytes can be stored. Because one Chinese Character occupies two bytes, only 10 Chinese characters can be stored, because an English character only occupies one byte, it can store 20 English halfwidth characters. In the full-width mode, only 10 Chinese characters can be entered, but only 10 English characters can be entered, because the full-width mode occupies two bytes.
Nvarchar typeThe nvarchar (20) is used to store the specific number of characters, indicating that it can store 20 characters.
Remember that when you develop a project, a binary stream truncation fault occurs on the current network due to the varchar data type, in short, the number after varchar refers to the number of bytes that can be stored, and the number after nvarchar indicates that multiple characters can be stored.