MySQL three major column types
Numeric type
Integral type: Tinyint
1 of bytes 8 Digit bit Storage Range 0---2^8-(0--255)
0000 0000 =0
1111 1111 =2^8-1=255
The computer in order to indicate a number is negative, will be the highest bit ( left ) of the 0/1, when fit to see
if the 0 is a positive number, if 1 , it is a negative number
0 0000000 0 1111111–>0->127
1 0000000 à -0 1 1111111 à -127
The question of twos complement
understand as above +0 and the -0 , the possibility of wasting a storage is repeated.
so the computer kind of negative, not according to "the absolute value of the back directly multiplied -1 get the "
Negative number = absolute value-128
So
1111 1111----. >-1
0000--- à -128
Smallint
Mediuint
Int
Bigint
Analysis:
2 bytes, - bit 0-----2^16-1=65535
-2^15-- à +2^15-1, -32768--- à 32767
in general, set a type N of bytes
N bytes, 8N bit.
0------ à 2^8n-1
-2^ (8n-1)--- à +2^ (8n-1);
for int Type: The more bytes that are occupied, the greater the range of storage
Int parameters for the declaration of the series:
( M ) unsigned zerofil
Learning tinyint parameters and verify the relationship of the byte to the range
Out of range out of range
that int without special instructions, the default is to comply with
# Plus unsigned represents unsigned, can affect the range of storage
# Plus unsigned type denotes unsigned
# Analysis M Parameters
#zerofill Zero is a 0 ; Fill Fill,
#M must and Zerofill cooperation is interesting, not enough digits, with 0 Fill
why add to 5 bit, because M to be 5 bit, so M with the Zerofill It's fun to work with.
decimal (floating-point / fixed-point type)
Floating-point numbers are more complex to represent in a computer.
Float ( m,d ) decimal ( m,d )
M called Precision ---- à represents the total number of decimal places, and D is the scale, representing the decimal place (the number of digits to the right of the decimal point)
Float(6,2) range -9999.99-------+9999.99
MySQL three major column types