mysql5.5列資料型別data type_測試

wisdomone1發表於2010-06-21
mysql> create table t1(a tinyint(30),b tinyint(3) zerofill);#建表指定zerofill,預設加上unsigned(正整數)
Query OK, 0 rows affected (0.04 sec)
mysql> desc t1;
+-------+------------------------------+------+-----+---------+-------+
| Field | Type                         | Null | Key | Default | Extra |
+-------+------------------------------+------+-----+---------+-------+
| a     | tinyint(30)                  | YES  |     | NULL    |       |
| b     | tinyint(3) unsigned zerofill | YES  |     | NULL    |       |
+-------+------------------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
 
 
 
 
#下列測試表明,如果插入的列值超出列的取值範圍,系統會插入對應列的的邊界值
,比如:
TINYINT[(M)] [UNSIGNED] [ZEROFILL]
一個很小的整數。有符號的範圍是-128到127,無符號的範圍是0到255。
mysql> desc t1;
+-------+----------------------+------+-----+---------+-------+
| Field | Type                 | Null | Key | Default | Extra |
+-------+----------------------+------+-----+---------+-------+
| a     | tinyint(30)          | YES  |     | NULL    |       |
| b     | tinyint(5)           | YES  |     | NULL    |       |
| c     | smallint(6) unsigned | YES  |     | NULL    |       |
+-------+----------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> insert into t1 values(6,-23768,567);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from t1;
+------+------+-------+
| a    | b    | c     |
+------+------+-------+
|    1 |    0 |     0 |
|    8 |    9 |   100 |
|    8 |    9 | 65535 |
|    8 |    9 |     0 |
|    6 | -128 |   567 |
+------+------+-------+
5 rows in set (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-665767/,如需轉載,請註明出處,否則將追究法律責任。

相關文章