Comparison of string types in the database

Source: Internet
Author: User

There are several types of strings defined in the database: Char, varchar, and nvarchar. The three types are different.

CHAR:

The length of the char type is fixed and the maximum length is 2000 characters. When a field is assigned a value, if the length of the string is smaller than the defined char type, the system automatically fills in the null value. When the value is exceeded, the value is truncated.

Varchar:

Compared with Char, varchar is longer, and its storage space varies according to your string length.

Nvarchar:

Nvarchar is a unicode variable-length type. The main difference between nvarchar and varchar is that it can store more characters in the same length. Unicode encoding uses two bytes to store any character. For example, varchar (3) and nvarchar (3) can store three characters (1.5 Chinese characters ), the latter can store three Chinese characters, which is the difference.

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.