Data type confusion: what is an int(11)?

Posted 功夫 熊猫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Data type confusion: what is an int(11)?相关的知识,希望对你有一定的参考价值。

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 |
+---------+

以上是关于Data type confusion: what is an int(11)?的主要内容,如果未能解决你的问题,请参考以下文章

没有估计器的 plot_confusion_matrix

What is “passive data structure” in Android/Java?

What is content-type and datatype in an AJAX request?

R-第8天

Coursera, Big Data 5, Graph Analytics for Big Data, Week 2 What is a Graph?

Coursera, Big Data 5, Graph Analytics for Big Data, Week 2 What is a Graph?