SQL connector Data Type

Source: Internet
Author: User

This morning I checked the data type of the SQL 2000 video system, but I am still a little confused about the following concepts. So I tried to summarize the differences between them!

I. Char and varchar

Char is of Fixed Length character type and varchar Variable Length character type. What is the difference between the two?

For example, we define char (10). If we insert ABC, even if there are less than 10 bytes, the database will add seven spaces to the end of ABC to less than 10 bytes. If we insert more than 10 bytes, the database will cut off the excess! That is to say, the Data Length of char is equal to the defined length!

In addition, char is distinguished between Chinese and English, and Chinese occupies two bytes in char, while English occupies one, so char (10) can only be 10 letters or 5 Chinese characters!

The length of a varchar is variable. For example, we have defined varchar (10). When we insert ABC, only three bytes are occupied in the database! 10 is only the maximum value. If you store less than 10 characters, it will not be filled with spaces! That is to say, the Data Length of varchar is smaller than or equal to the defined length!

The maximum storage range of char and varchar is 8000. Among them, varchar is mainly used to save space than char, but it is slightly less efficient than char, that is, to achieve efficiency, it is necessary to sacrifice some space, which is often said in the database design to change the efficiency of space ". But it doesn't mean that varchar is always better, and everything has two aspects. So when to use char and vchar, you still need to take it right!

Ii. nchar and nvarchar

Both nchar and nvarchar are Unicode-oriented standards. The two bytes are used as a storage unit, mainly for large storage capacity, such as our Chinese character! At the same time, they store a maximum range of 4000. The difference between the two is also a fixed length, and a non-fixed length.

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.