MySQL Optimization-data type width and mysql Data Type width

Source: Internet
Author: User

MySQL Optimization-data type width and mysql Data Type width

Reprinted please indicate the source: http://blog.csdn.net/l1028386804/article/details/46559861

You can specify the display width for All Integer Data Types in MYSQL.

Create a table
Create table tb_emp (id BIGINT (1 ))
The data type of the id field is BIGINT (1). Note the following number 1, which indicates the display width specified by the data type and the number of digits that can be displayed.
For example, if you declare a field of the INT type year int (4), this statement specifies that the data in the year field generally only shows the width of four digits.
The display width is irrelevant to the value range of the data type. The display width only specifies the maximum number of digits that MYSQL may display. When the number of digits is smaller than the specified width, spaces are filled. If a value greater than the display width is inserted, as long as the value does not exceed the value range of this type of integer, the value can still be inserted and displayed.
For example, if you insert a value of 19999 into the year field and use the select statement to query data, MYSQL displays a full value of 19999 with five digits instead of a four-digit value.
If the display width is not specified, MYSQL specifies the default width for each type.
Note: The display width is only used for display, and the value range and occupied space cannot be limited. For example, INT (3) occupies 4 bytes of storage space, in addition, the maximum value is not 999, but the maximum value allowed by the INT type.

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.