問題描述
我想知道 BigInt
、MediumInt
和 Int
之間的區別...更大的數字;但是,我可以制作一個 Int(20)
或一個 BigInt(20)
并且看起來它不一定與大小有關.
I was wondering what the difference between BigInt
, MediumInt
, and Int
are... it would seem obvious that they would allow for larger numbers; however, I can make an Int(20)
or a BigInt(20)
and that would make seem that it is not necessarily about size.
一些見解會很棒,只是有點好奇.我一直在使用 MySQL 一段時間,并在選擇類型時嘗試應用業務需求,但我從未理解這方面.
Some insight would be awesome, just kind of curious. I have been using MySQL for a while and trying to apply business needs when choosing types, but I never understood this aspect.
推薦答案
參見 http://dev.mysql.com/doc/refman/8.0/en/numeric-types.html
INT
是一個四字節的有符號整數.
INT
is a four-byte signed integer.
BIGINT
是一個八字節的有符號整數.
BIGINT
is an eight-byte signed integer.
它們每個接受的值都不能多于可以存儲在各自字節數中的值.這意味著 INT
中有 232 個值,BIGINT
中有 264 個值.
They each accept no more and no fewer values than can be stored in their respective number of bytes. That means 232 values in an INT
and 264 values in a BIGINT
.
INT(20)
和 BIGINT(20)
中的 20 幾乎沒有任何意義.這是顯示寬度的提示.它與存儲無關,也與列將接受的值范圍無關.
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, nor the range of values that column will accept.
實際上,它只影響 ZEROFILL
選項:
Practically, it affects only the ZEROFILL
option:
CREATE TABLE foo ( bar INT(20) ZEROFILL );
INSERT INTO foo (bar) VALUES (1234);
SELECT bar from foo;
+----------------------+
| bar |
+----------------------+
| 00000000000000001234 |
+----------------------+
對于 MySQL 用戶來說,看到 INT(20)
并假設它是一個大小限制,類似于 CHAR(20)
,這是一個常見的混淆源.事實并非如此.
It's a common source of confusion for MySQL users to see INT(20)
and assume it's a size limit, something analogous to CHAR(20)
. This is not the case.
這篇關于MySQL 中的類型:BigInt(20) 與 Int(20)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!