sql - -1 INT 列中是一个字符还是两个字符

标签 sql mysql

假设这个表

`publish` INT( 1 ) NOT NULL DEFAULT  '0'

此栏中可以输入-1、到-9吗?

最佳答案

是的。括号中的数字只是显示宽度:

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

特别是:

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. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using more than three digits.

INT 类型支持有符号和无符号整数。

关于sql - -1 INT 列中是一个字符还是两个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4637841/

相关文章:

php - 同一患者的不同订单号只能让我从 DB 获取一份

mysql - #1366 - 我的 nginx 服务器中的整数值 : '' for column. 不正确。 (mysql模式)

MySQL - 将表与主表连接两次

sql - 将两个表合并为一个输出

mysql - INSERT 插入行到现有表中

mysql - SQL: COUNT() 分组结果

c# - Mysql 到 Linq 查询

mysql - 输出显示为空

Mysql将列值视为选择的正则表达式

mysql - 如何在 Woocommerce 中删除具有相同产品 ID 的重复产品?