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:
The default integer type is the signed number.
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