Differences between varchar and nvarchar in MSServer

Source: Internet
Author: User

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.

Related Article

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.