1. Shaping is divided into four kinds of tinyint smallint mediumint int bigint
Attention:
The value range on the right is in the case where the unsigned keyword is not added, if unsigned is added, the maximum value is doubled, such as the tinyint unsigned value range (0~256).
Project Error Cases:
When it comes to acquiring a city as an identity.
found that more than 127 of region_id will take 127 to 127 (Oriental City), has been unable to find the reason, originally inserted region_id field type definition problem
Defined as: tinyint (4) Max 127 if plus unsigned can be increased to 256 direct change to smallint (5) maximum to 32767 display success!
There are four columns in the table:
field type, takes up bytes, allows storage of the minimum value, allows storage of the maximum value
Take the int type as an example, the byte count is 4byte, the byte (byte) is not the smallest unit stored by the computer, and there is a smaller unit than byte (byte), that is, bit, a bit represents a 0 or 1; 8 bits make up one byte; The general byte represents byte in uppercase B, and bits in lowercase b to indicate bit. Conversion of computer storage units: 1B=8B1KB=1024B1MB=1024KBThe number of bytes allowed to be stored according to the int type is 4 bytes, and we can convert an int UNSIGNED (unsigned) type to the minimum value of 0, the maximum value is 4294967295 (i.e. 4b=32b, the maximum value is 32 1 components);what does M mean in 2.INT (m)?M indicates the maximum display width. in int (m), thevalue of M is not related to how much storage space the Int (m) occupies . Int (3), int (4), and Int (8) All occupy 4 btyes of storage space on disk. To put it bluntly, the Int (M) is the same as the int data type except that the way it is displayed to the user is a little different.
Int (M) only with Zerofill can we see the difference clearly
@1. Creating a table T
Mysql> drop table if exists t; Mysql> CREATE TABLE t (ID int zerofill);
@2. Inserting data
mysql> INSERT into T (ID) values (10);
@3. Show select * FROM t
@4. Change field int (3)
Mysql>alter TABLE t change COLUMN ID ID INT (3) Zerofill;
Shown as:
@5. Inserting values that exceed a defined length
mysql> mysql> INSERT into T (ID) values (1000000);
From the above test can be seen:
(M) Specifies the width of the int type numeric display, if the field data type is int (4), then: "00" is added to the left when the value 10 o'clock is displayed;
When the value 100 is displayed, the left side should be "0";
When the value 1000000 is displayed, the specified width "(4)" has been exceeded, so it is output as -is.
This m=4 we can simply understand that we have built this length to tell the MySQL database that the data stored in this field is 4 digits wide, and of course if you are not 5 digits (as long as it is within the storage range of that type), MySQL can store it normally.
When defining, you need to be aware of the use of the unsigned symbol type, and then display the width value
MySQL data type-integer int (m)