MySQL - 整数列的大小限制 [英] MySQL - Size Limits to Integer Columns

查看:132
本文介绍了MySQL - 整数列的大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phpMyAdmin来创建我的表结构。

I'm using phpMyAdmin to create my table structures.

我可以从MySQL的文档页面上读到有关整数类型大小限制的信息:
< a href =http://dev.mysql.com/doc/refman/4.1/en/integer-types.html =noreferrer> MySQL整数类型参考

I can read from the documentation pages on MySQL about size limits for Integer Types: MySQL Integer Types Reference

所以这里是我对创建专栏感到困惑的地方。

So here is where I'm getting a little confused with creating a column.

I想要在表格中创建一个列: tbl_note_categories 名为 notescounter

I want to create a column in the table: tbl_note_categories called notescounter

我预计自己会在 tbl_notes 中使用任何特定的 categoryid 创建数千个音符。但我相信我会为每个categoryid创建数百个音符。

I don't foresee myself creating thousands of noteids in the tbl_notes with any specific categoryid. But I do believe I'd create hundreds of notes to each categoryid.

我正在选择:tinyint,smallint,mediumint。
根据上面的文档链接,我猜测smallint是我的最佳选择。

I'm at that point of choosing between: tinyint, smallint, mediumint. According the documentation link above, I'm guessing smallint is my best choice.

所以这是我的困惑。 PhpMyAdmin要求指定长度/值参数。
我要确保这个新列( notescounter )是无符号的,最多给我65536.
这是否意味着我需要长度/值为(5)?

So here's my confusion. PhpMyAdmin asks for a Length/Values parameter to be specified. I'm going to make sure this new column (notescounter) is unsigned, giving me up to 65536. Does that mean I need the Length/Values to be (5)?

我猜长度是字符长度,但我不确定。 (与varchar比较)

I'm guessing Length is character length, but I'm not sure. (comparing to varchar)

推荐答案

不,这是对MySQL的常见误解。实际上,长度对整数的大小或它可以存储的值的范围没有影响。

No, this is a common misconception about MySQL. In fact, the "length" has no effect on the size of an integer or the range of values it can store.


  • TINYINT 总是8位,可以存储2个 8 不同的值。

  • SMALLINT 总是16位,可以存储2个 16 不同的值。

  • INT 是总是32位,可以存储2个 32 不同的值。

  • BIGINT 总是64位并且可以存储2 64 不同的值。

  • TINYINT is always 8 bits and can store 28 distinct values.
  • SMALLINT is always 16 bits and can store 216 distinct values.
  • INT is always 32 bits and can store 232 distinct values.
  • BIGINT is always 64 bits and can store 264 distinct values.

还有一个MEDIUMINT,但是工作在MySQL上的工程师告诉我MEDIUMINT总是在内部被提升为32位INT,因此使用MEDIUMINT实际上没有任何好处。

There's also a MEDIUMINT, but the engineers who work on MySQL tell me MEDIUMINT always gets promoted to a 32-bit INT internally, so there's actually no benefit to using MEDIUMINT.

长度用于显示,并且这只有在你使用 ZEROFILL 选项时才有意义。

The length is only for display, and this only matters if you use the ZEROFILL option.

请参阅我对在INT(10)和INT(12)之间有什么区别(当应用于我的代码时)?

这篇关于MySQL - 整数列的大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆