The difference between char, varchar, and nvarchar

Source: Internet
Author: User

First, char, varchar, and nvarchar, text, and ntext are all text data types in the database, then differentiate between the Var prefix and the n prefix. Text and ntext have been generally replaced by varchar (max) and nvarchar (max), so they are not generally used.

Char

Represents an immutable length, and if the assigned value is not sufficient to specify the number of digits, the end is padded with spaces.

varchar
Represents a variable length, if the assigned value is not sufficient to specify the number of digits, the actual assigned value will prevail.

nvarchar
The n prefix represents the Unicode encoding standard. If it is with N, then each character occupies 2 bytes. If you do not have n, the English character occupies 1 bytes, and the Chinese byte is two bytes (that is, Unicode encoding format). commonly used in the development process is nvarchar rather than varchar, is to avoid the compatibility of Chinese and English.

When it is possible to accurately control the length of text bytes, using char is more efficient than using nvarchar, reducing the time cost of calculating text length and increasing the storage cost (but it is not a big problem in the case of low storage costs).

The difference between char, varchar, and nvarchar

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.