首页/Home 数据库 Configuration INT(1) Or INT(11) Matters

INT(1) Or INT(11) Matters

PrintE-mail
Monday, 25 August 2008 05:40  

I asked several people, even the PHP mailing-list,  about the difference between int(1) and int(11) when creating a MySQL table, The answer is little difference: 1 and 11 (in this case), are used to specify the display width. However, there is a little more.

I checked manual,

The manual says:

Another extension is supported by MySQL for optionally specifying the display width of integer data types
in parentheses following the base keyword for the type (for example, INT(4)). This optional display width
is used to display integer values having a width less than the width specified for the column
by left-padding them with spaces. 

And we all see that.

But, it's better to read on. While you read on, you may often find something.

Just after it explained ZEROFILL, it says:

Note that if you store larger values than the display width in an integer column, you may
experience problems when MySQL generates temporary tables for some complicated joins,
because in these cases MySQL assumes that the data fits into the original column width. 

So, that's the more important difference.

And, in production systems, though I haven't met the problem. I think it's always a better practice to specify the width you need, rather than just INT.

 

回复

留个脚印儿吧.


回复