這個代表顯示寬度
整數列的顯示寬度與mysql需要用多少個字符來顯示該列數值,與該整數需要的存儲空間的大小都沒有關系,比如,不管設定了顯示寬度是多少個字符,bigint都要占用8個字節。
int是整型,(11)是指顯示字符的長度,但要加參數的,最大為255,比如它是記錄行數的id,插入10筆資料,它就顯示00000000001 ~~~00000000010,當字符的位數超過11,它也只顯示11位,如果你沒有加那個讓它未滿11位就前面加0的參數,它不會在前面加0
聲明整型數據列時,我們可以為它指定個顯示寬度M(1~255),如INT(5),指定顯示寬度為5個字符,如果沒有給它指定顯示寬度,MySQL會為它指定一個默認值。顯示寬度只用於顯示,並不能限制取值范圍和占用空間,如:INT(3)會占用4個字節的存儲空間,並且允許的最大值也不會是999,而是INT整型所允許的最大值。
MySQL有五種整型數據列類型,即TINYINT,SMALLINT,MEDIUMINT,INT和BIGINT。它們之間的區別是取值范圍不同,存儲空間也各不相同。
在整型數據列後加上UNSIGNED屬性可以禁止負數,取值從0開始。
int范圍
Type
Bytes
Minimum Value
Maximum Value
(Signed/Unsigned)
(Signed/Unsigned)
TINYINT
1
-128
127
0
255
SMALLINT
2
-32768
32767
0
65535
MEDIUMINT
3
-8388608
8388607
0
16777215
INT
4
-2147483648
2147483647
0
4294967295
BIGINT
8
-9223372036854775808
9223372036854775807
0
18446744073709551615
下面為官網的說明
代碼如下 復制代碼Be careful when considering ENUM('T','F') as "true binary".
Example:
CREATE TABLE `bits` (
`val` ENUM('T','F') NOT NULL
);
mysql> INSERT INTO `bits` (`val`) VALUES ('W'), ('T'), ('F');
Query OK, 3 rows affected, 1 warning (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 1
mysql> SHOW WARNINGS;
+---------+------+------------------------------------------+| Level | Code | Message |+---------+------+------------------------------------------+| Warning | 1265 | Data truncated for column 'val' at row 1 |+---------+------+------------------------------------------+1 row in set (0.00 sec)
mysql> SELECT COUNT(DISTINCT val) FROM bits;
+---------------------+| COUNT(DISTINCT val) |+---------------------+| 3 |+---------------------+1 row in set (0.00 sec)
Well, shouldn't a binary type have only two distinct values?
(Note that it isn't NULL.)
Explanation from manual (10.4.4. The ENUM Type):
-----
If you insert an invalid value into an ENUM (that is, a string not present in the list of permitted values), the empty string is inserted instead as a special error value. This string can be distinguished from a “normal” empty string by the fact that this string has the numeric value 0. More about this later