Required Storage and Range for Integer Types Supported by MySQL
| Type | Storage (Bytes) | Minimum Value Signed | Minimum Value Unsigned | Maximum Value Signed | Maximum Value Unsigned |
|---|---|---|---|---|---|
TINYINT | 1 | -128 | 0 | 127 | 255 |
SMALLINT | 2 | -32768 | 0 | 32767 | 65535 |
MEDIUMINT | 3 | -8388608 | 0 | 8388607 | 16777215 |
INT | 4 | -2147483648 | 0 | 2147483647 | 4294967295 |
BIGINT | 8 | -2的63方 | 0 | 2的63方-1 | 2的64方-1 |
TINYINT
TINYINT[(M)] [UNSIGNED] [ZEROFILL]
A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.
SMALLINT
A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.
MEDIUMINT
MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL]
A medium-sized integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.
INT
INT[(M)] [UNSIGNED] [ZEROFILL]
A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
INTEGER
INTEGER[(M)] [UNSIGNED] [ZEROFILL]
This type is a synonym for INT.
BIGINT
BIGINT[(M)] [UNSIGNED] [ZEROFILL]
A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.
SERIAL
SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.
DEMO
create table serial_test (id SERIAL);

从图可知,是无符号的bigint类型,不能为空,主键,自动增长
1个表中,指定多个字段为serial,会报错(Incorrect table definition; there can be only one auto column and it must be defined as a key)
BOOL, BOOLEAN
These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true.
0是fase,不为0是true
最后
以上就是友好夏天最近收集整理的关于Int Data Type Syntax的全部内容,更多相关Int内容请搜索靠谱客的其他文章。
发表评论 取消回复