Mysql Study Notes 5 ----- field data type
I. numeric type
Integer:
Tinyint 1 byte
Smallint 2 bytes
Mediumint 3 bytes
Int/intege 4 bytes
Bigint 8 bytes
You can use unsigned to control whether there are positive and negative values.
Zerofill can be used for leading zero-padding.
The bool type exists, which is actually the alias of tinyint (1 ).
Create table tb1_int (
A tinyint unsigned,
B tinyint
);
Alter table tb1_int add c tinyint (2) zerofill; // The display width must be matched with zerofill to see the effect.
Type (M ),M is the minimum display widthIs not a value range. If the insert width is greater than M, it will not be affected and will be displayed directly.
Zerofill is the leading zero fill. When the number of digits is less than the minimum width, the leading zero is automatically added.
If it is male or female, tinyint (1) is not recommended.
Decimal point (floating point number ):
Single precision: float: 4 bytes
Double precision: double: 8 bytes
123.456 disk storage: 0.123456*10 ^ 3
The values 0.123456 and 3 need to be saved, which are precision and power.
Create table num_2 (
A float,
B double
);
Intsert into num_2 values (1234567890.0123456789, 1234567890.0123456789 );
Select * from num_2;
The results show that:
The default precision of a single precision is about 6 bits, and that of a double precision is about 16 bits by default.
Decimals support writing in this way
Type (M, D)
M indicates a total of M bits
D indicates the number of digits occupied by decimal places.
Create table num_3 (
A float (5, 3 ),
B double (7,3)
);
Insert into num_3 values (0.12345E3, 0.1234567E3); // supports insertion of scientific notation. the singular number is limited by (M, D.
Decimal (number of points)
Decimal (M, D)
The default value is decimal (), M is 65, and D is 30.
If the number of decimal places in the number of stored points is greater than two, the number is rounded to five.
Zerofill is supported. Unsigned is supported, but not needed.