在MySQL中使用INT(1)和TINYINT(1)有区别吗? [英] Is there a difference in using INT(1) vs TINYINT(1) in MySQL?

查看:934
本文介绍了在MySQL中使用INT(1)和TINYINT(1)有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设INT(1)与TINYINT(1)完全相同,但我真的不知道。每当我的值只能是一个整数(例如值0-9)时,我总是只使用INT(1)来表示它是一个整数而且它只是一个字符,我认为这意味着它只能是0到9的值(如果我错了,请向我解释)。我总是忽略你可以将数字转换为其他类型的INT。我不懂MySQL并且倾向于避免使用它可以做的更复杂的事情。

I'm under the assumption that INT(1) is the exact same thing as TINYINT(1) but I really have no idea. Whenever I've had values that can only be a single integer (e.g. a value 0-9), I've always just used INT(1) to say it's an integer and it will only be one character, which I assume means that it could only be a value 0 through 9 (please explain this to me if I'm wrong). I've always just ignored the other types of INT that you can cast the number as. I'm no MySQL savvy and tend to avoid the more complicated things you can do with it.

所以我的问题是,各种整数之间是否有任何区别如果为每种类型定义长度为1,则键入INT,TINYINT,SMALLINT,MEDIUMINT和BIGINT;?如果没有,我是否应该使用它们(我可以看到使用它们以获得更多语义含义,TINYINT更具体而不仅仅是INT)?如果是这样,我可以轻松地(和/或我应该)通过我的数据库并将我的所有INT(1)字段更改为TINYINT(1)字段吗?

So my question, is there any difference between the various integer types INT, TINYINT, SMALLINT, MEDIUMINT, and BIGINT if you define a length of 1 for each type;? If not, should I use them anyways (I can see using them for more semantic meaning, TINYINT being more specific than just INT)? If so, could I easily (and/or should I) just go through my database and change all my INT(1) fields to TINYINT(1) fields?

推荐答案

整数列类型括号中的数字是显示宽度。这不会影响存储要求,因为它们是预先定义的。

The number in parentheses for integer column types is the "display width". This does not effect the storage requirements as they are pre-defined.

进一步阅读

  • http://dev.mysql.com/doc/refman/5.0/en/data-types.html
  • http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

这篇关于在MySQL中使用INT(1)和TINYINT(1)有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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