Meaning of specifying length for integer and string types in MySQL

Source: Internet
Author: User
Introduced:

What do the numbers in int (5) and char (5) or varchar (5) mean? Is the number of bytes, or the length of the character? Why is an int (5) specified in an integral type, but you can enter 123456?

The answer is the latter, whether it is an integer or a string type, followed by the number is the character length, that is, the number of characters, and it should be emphasized that the number specified after the integer refers to the minimum display length, that is, to display the value of the minimum number of characters, If the actual value of the number of characters is less than the number set after the previous field, it will be filled with 0 in front of value (at the same time to add a constraint to the field Zerofill, use Select to see the real results); If the value of the number of characters is greater than the number of , it will also appear as normal because the specified value is the display length, not the storage length, and the default storage length of the integer type is 11 characters, which satisfies the majority of the environment, so it is not necessary to specify a value after int, even if it is specified.

Use the int type in a sentence, specifying a length of only display length, not a storage length, and a storage length of 11 characters by default, so you do not need to specify the length of the int type.

The number after the string type refers to the stored length of the character, that is, the number of characters stored cannot exceed this limit, otherwise it cannot be inserted.

Meaning of specifying length for integer and string types in MySQL

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.