Course: understanding of varchar and nvarchar

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.