In-depth explanation of differences between fixed-length char (n) and variable-length varchar (n) in SQL Server

Source: Internet
Author: User

Char (n) is a fixed-length format. The field in the format of char (n) occupies a fixed width of n characters. If the actual length of the stored data exceeds n, the excess data is truncated, if the length is less than n, it will be filled with null characters.

Varchar (n) is a variable-length format. Fields in this format allocate space based on the actual data length, without wasting space. However, it is troublesome to search data quickly.

Generally, as long as a table has a field defined as varchar (n), the other fields defined using char (n) are actually varchar (n.

If your length is not long, for example, 3 ~ 10 characters, so the char (n) format is more efficient and the search speed is faster. However, if some data is very long and some data is relatively short, such as the profile of the registered user, there is no way to do it, and you are very concerned about the waste of space, then the varchar (n) format is used.

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.