Data type confusion: what is an int(11)?
2018-06-17 23:03:08来源:未知 阅读 ()
http://everythingmysql.ning.com/profiles/blogs/data-type-confusion-what-is-an
Over and over I see customers that don't understand what int(11)
really means. Their confusion is understandable. Many know what defining a char(10)
means (a fixed-sized character string that allows up to 10 characters). However, ints are different.
First of all, there are 5 types of integer. They are all fixed size.
Type | # of bytes |
tinyint | 1 |
smallint | 2 |
mediumint | 3 |
int | 4 |
bigint | 8 |
As you can see from the chart, an int
is always 4 bytes. That can store signed numbers from -2 billion to +2 billion (and unsigned numbers 0 to 4B). So, what does it mean if you declare an int(5)
? It does not restrict the number of digits to 5... It may actually do nothing! The (5) part is a display width. It's only used if you use UNSIGNED and ZEROFILL with an integer type. Then the display of those numbers will be zero-padded on the left to 5 digits if they contain less than 5 digits. Example:
CREATE TABLE `foo` (
`bar` int(5) unsigned zerofill DEFAULT NULL
)
SELECT * FROM foo; +---------+
| bar |
+---------+
| 00042 |
| 00101 |
| 9876543 |
+---------+
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- JavaScript常用方法封装 2019-08-09
- 数据库概念介绍 2019-07-24
- 01、MySQL_简介 2019-07-24
- Mysql错误积累001-load data导入文件数据出现1290错误 2018-08-02
- 压缩数据库日志 2018-07-13
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash