mysql 类型 bigint,MySQL中的类型:BigInt(20)与Int(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.

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.

解决方案INT is a four-byte signed integer.

BIGINT is an eight-byte signed integer.

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.

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.

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 |

+----------------------+

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Bigint类型可以存储比int类型更大的整数,Bigint类型可以存储范围从-9223372036854775808到9223372036854775807之间的数字,而int类型只能存储范围从-2147483648到2147483647之间的数字。 ### 回答2: MySQLbigintint是整数数据类型的两个选项。它们之间的区别如下: 1. 数据范围:bigint的取值范围更广,可以存储的整数范围从-2^63到2^63-1,而int的取值范围从-2^31到2^31-1。这意味着bigint可以存储更大的整数值。 2. 存储空间:bigint需要更多的存储空间来存储相同数量的数据。bigint使用8个字节(64位),而int只使用4个字节(32位)。因此,如果要存储更大的整数数据集,bigint会占用更多的磁盘空间。 3. 性能:由于bigint使用更多的存储空间,它可能会在大量数据处理时影响查询的性能。相比之下,int数据类型可以更快地执行查询操作。 4. 应用场景:由于bigint可以存储更大的整数值,所以在处理需要大范围整数的应用程序时更常见。例如,在存储用户ID时,bigint可能更合适,因为用户ID可能会非常庞大。 总的来说,bigintint之间的主要区别是存储范围和存储空间。根据具体的应用场景和需求,我们可以选择合适的数据类型来存储整数数据。 ### 回答3: BigIntInt都是MySQL的整数数据类型,不同之处在于它们的存储范围和占用空间。 1. 存储范围: - Int是一个4字节(32位)有符号整数,其存储范围为-2,147,483,648到2,147,483,647。 - BigInt是一个8字节(64位)有符号整数,其存储范围为-9,223,372,036,854,775,808到9,223,372,036,854,775,807。 2. 占用空间: - 由于BigInt的存储范围比Int更大,所以它需要更多的存储空间。Int占用4个字节(32位),而BigInt占用8个字节(64位)。 3. 适用场景: - 如果你的数据范围可以在Int的存储范围内完成,那么使用Int可能是更好的选择,因为它占用更少的空间。 - 如果你需要存储非常大的整数或需要更大的存储范围,那么使用BigInt是更合适的选择。 总结:BigInt提供了更大的存储范围,但相应地占用更多的存储空间。选择使用哪个数据类型取决于你的数据的范围和你对空间利用率的考虑。如果你不确定应该使用哪个数据类型,可以根据你的需求来评估并选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值