Some time ago, I found a problem during the test. After reading the log, I found that an exception occurred while inserting data into the database!
The reason is that the inserted string is too long and the type used in the project is nvarchar. The following is their understanding:
1. varchar-number of bytes
Example: varchar (10)-[two bytes in Chinese]
The definition above indicates that the number of bytes I have stored is 10, so 10 can be saved in English, and only 5 can be saved in Chinese!
2. nvarchar -- number of characters
Example: nvarchar (10)-[two bytes in Chinese]
As defined above, we can store 10 characters in English and 10 characters in Chinese!
If nvarchar is understood as the number of characters, it is easy to understand the rules for storing Chinese characters.
3. Summary:
|
|
English |
Chinese |
Varchar (N) |
Bytes |
N |
N/2 |
Nvarchar (N) |
Character Count |
N |
N |
For more in-depth understanding of them, refer to the following reference:Article.
References:
1.Differences between varchar and nvarchar
2.Differences between char, varchar, text, nchar, nvarchar, and ntext
To synchronize:Personal document Directory Index