mysql中int型的zerofill参数
生活随笔
收集整理的這篇文章主要介紹了
mysql中int型的zerofill参数
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
mysql> select * from college_view; +-------------+--------------+-------------+------------+ | student_num | student_name | student_age | department | +-------------+--------------+-------------+------------+ | 901 | 張三 | 20 | 外語 | +-------------+--------------+-------------+------------+ 1 row in set (0.00 sec)mysql> show create table college; +---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | college | CREATE TABLE `college` (`number` int NOT NULL,`name` varchar(20) NOT NULL,`major` varchar(20) DEFAULT NULL,`age` int DEFAULT NULL,PRIMARY KEY (`number`),UNIQUE KEY `number` (`number`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)?插入一條記錄,然后查詢記錄,可以發(fā)現(xiàn)
mysql> insert into college_view-> values (0901,'張三',20,'外語'); Query OK, 1 row affected (0.00 sec) mysql> select * from college; +--------+--------+--------+------+ | number | name | major | age | +--------+--------+--------+------+ | 901 | 張三 | 外語 | 20 | +--------+--------+--------+------+ 1 row in set (0.00 sec)書本上的number字段都是四位數(shù)字,高位是0,想達(dá)到這樣的效果,必須高位用0填補(bǔ),使用zerofill參數(shù),
所以更改表college的number字段 ,代碼如下:
mysql> alter table college -> modify number int(4) zerofill; Query OK, 1 row affected, 2 warnings (0.06 sec) Records: 1 Duplicates: 0 Warnings: 2接下來繼續(xù)查詢表和視圖,發(fā)現(xiàn)number字段高位全部變成0填充了:
mysql> select * from college; +--------+--------+--------+------+ | number | name | major | age | +--------+--------+--------+------+ | 0901 | 張三 | 外語 | 20 | +--------+--------+--------+------+ 1 row in set (0.00 sec)mysql> select * from college_view; +-------------+--------------+-------------+------------+ | student_num | student_name | student_age | department | +-------------+--------------+-------------+------------+ | 0901 | 張三 | 20 | 外語 | +-------------+--------------+-------------+------------+ 1 row in set (0.00 sec)?
總結(jié)
以上是生活随笔為你收集整理的mysql中int型的zerofill参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++vector初始化的几种方法
- 下一篇: linux cmake编译源码,linu