mysql zerofill 的使用


轉自:http://www.jquerycn.cn/blog/mysql/

那這個int[M]中M是什么意義喃,在定義數值型數據類型的時候,可以在關鍵字括號內指定整數值(如:int(M),M的最大值為255)顯示最大顯示寬度,顯示寬度M與數據所占用空間,數值的范圍無關。 如果在定義字段的時候指定zerofill,那么當數值的顯示寬度小於指定的列寬度時候,則默認補充的空格用0代替。

mysql> create table int_12(id int(12) zerofill);
Query OK, 0 rows affected (0.13 sec)

mysql> desc int_12;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type                      | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id    | int(12) unsigned zerofill | YES  |     | NULL    |       |
+-------+---------------------------+------+-----+---------+-------+
1 row in set (0.01 sec)

mysql> insert into int_12 (id) values(1);
Query OK, 1 row affected (0.00 sec)
mysql> select * from int_12;
+--------------+
| id           |
+--------------+
| 000000000001 |
+--------------+
1 row in set (0.00 sec)

mysql> alter table int_12 change id id int(23) zerofill;
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> select * from int_12 ;
+-------------------------+
| id                      |
+-------------------------+
| 00000000000000000000001 |
+-------------------------+
1 row in set (0.00 sec)

注意在navicate或者phpmyadmin中顯示數據顯示可能不正確,如果你加了zerofill,但是沒有補充0,可以到mysql命令行中看下


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM