String type: For varchar(M), M is the maximum character that can be stored in the field String, that is to say the field length. Depending on the settings, when the value you insert exceeds the length of the field setting, you are likely to receive an error prompt. If you do not receive a prompt, the inserted data may also be automatically truncated to fit the predefined length of the field. Everything like varchar(5) means that the length of the stored string cannot exceed 5.
Numeric column type: The length modifier indicates the maximum width and has nothing to do with the physical storage of the field, that is, when tinyint(1) and tinyint(4) are signed The storage range is -128 to 127 (without a sign, it is 0 to 255).
Note: The signed default range (-128~127), the default length is 4.
# #If zerofill is used, when the actual length does not reach the specified display length, it will be filled in front with 0.
In the data type of MySQL, tinyin is related to whether it is signed or not. The signed value range is -128~127. The unsigned value range is 0~255. The number in parentheses has nothing to do with the stored value, only the display width in some cases.
2 Test
#What happens when the name field of the string type is set to a length exceeding 5 ?
What happens when the tinyint type (signed) age field is set outside the range (-128~127)?
1 bytes = 8 bit, the maximum length of data that can be represented by one byte is 2 to the 8th power 11111111. Also in computers It is
-128 to 127
1.BIT[M]
bit field type, M represents the number of digits in each value, ranging from 1 to 64, if M Ignored, defaults to 1
2.TINYINT[(M)] [UNSIGNED] [ZEROFILL] M defaults to 4
, a small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.
3. BOOL, BOOLEAN
is a synonym for TINYINT(1). A value of zero is considered false. Non-zero values are considered true.
4.SMALLINT[(M)] [UNSIGNED] [ZEROFILL] M defaults to a small integer of 6
. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.
5.MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL] M defaults to 9
A medium-sized integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.
6. INT[(M)] [UNSIGNED] [ZEROFILL] M defaults to 11
A normal-sized integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
7.BIGINT[(M)] [UNSIGNED] [ZEROFILL] M defaults to 20
big integer. The symbolic interval is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.
Note: The M here does not represent the specific length stored in the database. In the past, I always mistakenly thought that int(3) can only store 3-length numbers, int(11) will store 11-length numbers, which is totally wrong.The above is the detailed content of What is the difference between tinyint(1) and tinyint(4) in Mysql. For more information, please follow other related articles on the PHP Chinese website!