MySQL data type

Source: Internet
Author: User

Numeric type Integer type

When the inserted value exceeds the range of the type, only the maximum range value is retained.

Whether the constraint type is signed or unsigned:

    1. The default integer type is the signed number.

    2. Specify unsigned unsigned

Example: CREATE table t1 (x tinyint unsigned) Note: tinyint has a signed range of 128 to 127, unsigned 0 to 255.

"Focus" for the type of shaping, the MySQL width limit is not a limited type of numerical width, but rather limit the display width, (that is, when querying with the SELECT statement, the width of the table display, only the value is less than the limit width of the effect, beyond the width value, by the actual length of the value display)

add Zerofill at the end of the statement, the expression is populated with 0. For example:Create TableT1 (IDint(5) unsigned zerofill); Create a table of type int with a width of 5 unsigned and a lesser bit with 0 added. ======To test the display width of an integer type with Zerofill=============MariaDB[DB1]> Create TableT7 (Xint(3) Zerofill); MariaDB[DB1]> Insert  intoT7Values     -(1),     -( One),     -(111),     -(1111); MariaDB[DB1]> Select *  fromT7;+------+|X|+------+|  001 ||  011 ||  111 || 1111 |#超过宽度限制仍然可以存+------+

The storage width of int is 4 bytes, or 32 bit, i.e. 2**32
The unsigned maximum value is: 4294967296-1
Signed Maximum: 2147483648-1
Signed and unsigned maximum numbers require a display width of 10 and 11 bits for a signed minimum value to display completely, so the default display width of int type is 11 is very reasonable

Finally: the type of shaping, in fact, there is no need to specify the display width, using the default is OK

MySQL data 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.