mysql int 字段不截断

发布于 2024-10-05 00:37:53 字数 173 浏览 0 评论 0原文

众所周知,当您描述 varchar 或整数字段时,您应该设置它们的长度...

类似 int(5) 或 varchar(5)...

但是当您尝试将 123456 添加到这两个字段时...而 varchar 字段截断值,整数字段不会截断它......

那么描述 int 长度的目的是什么?

as all you know, when you describe varchar or integer fields you should set the length of them...

something like int(5) or varchar(5)...

but when you try add 123456 to both fields.. while varchar field truncates the value, integer field does not truncate it...

so what's the aim of describing int length?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

只为守护你 2024-10-12 00:37:54

看来这个“长度”仅用于显示: http:// /dev.mysql.com/doc/refman/5.0/en/numeric-types.html

例如,INT(4)指定显示宽度为四位的INT。应用程序可以使用此可选显示宽度来通过用空格向左填充宽度来显示宽度小于为列指定的宽度的整数值。 (也就是说,这个宽度存在于随结果集返回的元数据中。是否使用它取决于应用程序。)

It appears this "length" is used for display only: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

For example, INT(4) specifies an INT with a display width of four digits. 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. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)

驱逐舰岛风号 2024-10-12 00:37:54

INT 类型的大小既不是位也不是字节。这只是当字段指定了 ZEROFILL 时使用的显示宽度。

请参阅这篇博客文章 进行深入解释。

The size of the INT type is neither bits nor bytes. It's just the display width that is used when the field has ZEROFILL specified.

See this blog article for an in depth explanation.

清旖 2024-10-12 00:37:54

10.2 开始。数字类型

MySQL 支持以下扩展:
可选地指定显示
整数数据类型的宽度
基本关键字后面的括号
对于类型。例如,INT(4)
指定具有显示宽度的 INT
四位数字。此可选显示
应用程序可以使用宽度来
显示具有宽度的整数值
小于指定的宽度
向左填充列
空间。 (也就是说,这个宽度是
存在于返回的元数据中
结果集。不管用还是没用
取决于应用程序。)

显示宽度不受限制
可存储的值范围
在专栏中。也不能阻止
值比列显示宽
宽度无法正确显示。

FRom 10.2. Numeric Types

MySQL supports an extension for
optionally specifying the display
width of integer data types in
parentheses following the base keyword
for the type. For example, INT(4)
specifies an INT with a display width
of four digits. 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. (That is, this width is
present in the metadata returned with
result sets. Whether it is used or not
is up to the application.)

The display width does not constrain
the range of values that can be stored
in the column. Nor does it prevent
values wider than the column display
width from being displayed correctly.

七月上 2024-10-12 00:37:53

int(5) 并不像您想象的那样:它指定一个显示宽度为 5 位数字的整数字段,即小于 5 位数字的数字将被填充空格字符。

在 MySQL 中,int 值始终为 4 字节宽,范围为 -2,147,483,648 到 2,147,483,647。

请参阅http://dev.mysql.com/doc/refman/ 5.0/en/numeric-types.html

int(5) does not do what you think it does: it specifies an integer field with a display width of 5 digits, i.e. numbers shorter than 5 digits will be padded with space characters.

In MySQL, int values are always 4 bytes wide and can go from -2,147,483,648 to 2,147,483,647.

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

枕头说它不想醒 2024-10-12 00:37:53

INT(N)中的N,表示应用程序显示长度;由于语法与 VARCHAR(N) 相似,这是非常具有误导性的,并且可以理解,经常被误解。对于我见过的所有应用程序来说,它实际上毫无意义。

这适用于所有 TINYINTSMALLINTMEDIUMINTINTBIGINT

The N in INT(N), indicating application display length; is was very misleading, due to the syntax similarity to VARCHAR(N), and understandably, often misunderstood. It's effectively meaningless for all applications I've seen.

This goes for all TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文