1. 程式人生 > >tinyint,smallint,int,bigint後面括號的含義

tinyint,smallint,int,bigint後面括號的含義

tinyint存1個位元組(unsigned 存0--255,無 存-128 --127) smallint存2個位元組(unsigned 存0—65535 ,無 存-32768--32767) int存4個位元組(unsigned 存2的32次方,無 存-2的31次方 –2的31次方-1) bigint存8個位元組(unsigned 存2的64次方,無 存-2的63次方 –2的63次方-1)

做個實驗: mysql> create table bb(a int(1) zerofill,b int(2) zerofill,c int(3) zerofill); Query OK, 0 rows affected (0.18 sec) mysql> show create table bb; CREATE TABLE bb

 ( aint(1) unsigned zerofill DEFAULT NULL, b int(2) unsigned zerofill DEFAULT NULL, cint(3) unsigned zerofill DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 三個欄位括號中的引數不同,分別都加了zerofill,我們來看下有什麼影響 mysql> insert into bb values(1,1,1); Query OK, 1 row affected (0.00 sec)

mysql> select * from bb;

abc
101001

1 row in set (0.00 sec)

mysql> alter table bb add d int(4); Query OK, 1 row affected (0.27 sec) Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from bb;

abcde
101001NULLNULL

1 row in set (0.00 sec)

mysql> update bb set d =1,e =1 where a=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from bb;

abcde
10100111

1 row in set (0.00 sec)

由此可見:括號中的數字表示資料庫中顯示數字的位數,一般情況下不起左右,只有在zerofill情況下才會起作用。