SQL Server re-learning (1) -- Differences Between varchar, nvarchar, and char, varcharnvarchar

Source: Internet
Author: User

SQL Server re-learning (1) -- Differences Between varchar, nvarchar, and char, varcharnvarchar

SQL Server cannot be lost. review it;
Character data with a variable length of n Bytes and non-Unicode length. N must be a value between 1 and 8,000. The storage size is the actual length of the input data bytes, rather than n Bytes. Nvarchar (n) contains variable-length Unicode characters of n characters. The value of n must be between 1 and 4,000. The storage size of bytes is twice the number of input characters. The two fields have Field Values: I and coffee, so the varchar field occupies 2 × 2 + 6 = 10 bytes of storage space, the nvarchar field occupies 8 × 2 = 16 bytes of storage space.

If the field value is only in English, you can select varchar. If the field value contains many double-byte (Chinese, Korean, etc.) characters, use nvarchar. If the char length is insufficient, use spaces.

Error example: If char is used for storing the user name, if the length is not enough for comparison, for example, if the length of "admin" is 5, it is set to char (10 ), there will be five spaces after the retrieved admin.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.