Mysql的BigInt(20),Int(20)以及Bigint(32)有區別嗎?

原文: http://stackoverflow.com/questions/3135804/types-in-mysql-bigint20-vs-int20-etcchtml

http://dev.mysql.com/doc/refman/5.1/en/numeric-types.htmlmysql

 

Types in MySQL: BigInt(20) vs Int(20) etcc

 

See http://dev.mysql.com/doc/refman/5.1/en/numeric-types.htmlgit

INT is a four-byte signed integer. BIGINT is an eight-byte signed integer.sql

The 20 in INT(20) and BIGINT(20) means almost nothing. It's a hint for display width, it has nothing to do with storage. Practically, it affects only the ZEROFILL option:app

 

Sql代碼   收藏代碼
  1. CREATE TABLE foo ( bar INT(20) ZEROFILL );  
  2. INSERT INTO foo (bar) VALUES (1234);  
  3. SELECT bar from foo;  
  4.   
  5. +----------------------+  
  6. | bar                  |  
  7. +----------------------+  
  8. | 00000000000000001234 |  
  9. +----------------------+  
 

 

The number in parentheses in a type declaration is display width , which is unrelated to the range of values that can be stored in a data type. Just because you can declare Int(20) does not mean you can store values up to 10^20 in it:less

[...] 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. ...ide

The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters.post

For a list of the maximum and minimum values that can be stored in each MySQL datatype, see here .網站

 

Mysql的數字類型(1B,2B,3B,4B,8B都有)

一個INT,佔4個字節,跟JAVA中的int同樣,即便是有符號也能表達21億 這麼大的數據。 因此平時絕大多數狀況,包括大型網站的UID,都用不了這麼大的數據,好友關係表可能會超過,關係表能夠考慮用BIGINT。還有就是平時時間戳須要用BIGINT。總之,不要輕易用上BIGINT,徹底是浪費!url

相關文章
相關標籤/搜索