在mysql中

mysql  

那 int(5) 跟 smallint(5)有什麼差別呢?

以下摘至mysql官方manual

MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)

The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using more than three digits.

 

由上面的說明, 我們可以知道int(5)跟smallint(5)的差別在於"佔用的空間"以及"極小值跟極大值"

int佔了4 bytes, min=-2147483648 , max=2147483647

或者unsigned int佔了4bytes , min=0 , max=4294967295

 

smallint佔了2 bytes, min=-32768 , max=32767

或者unsigned smallint佔了2 bytes , min=0 , max=65535

 

而括號裡面的5, 只代表了可顯示的數字長度都是5個, 不管是int或smallint都一樣!!

差別在於int(5)可以顯示65537 , 而smallint(5)只能顯示65535

因為smallint的unsigned max是65535.... 超過就會..............  不要問 , 很恐怖  =  ="

 

 

just kidding....  超過極限值, 當然就會爆掉或者是轉成補數的型式

arrow
arrow
    全站熱搜

    js 發表在 痞客邦 留言(0) 人氣()