decimal 占位吗 负数_mysql – 用于存储负数的正确数据类型

我必须保存值-1.使用tinyint(1)或tinyint(2)的数据类型更正确吗?为什么?

我知道我也可以使用tinyint tinyint(1)存储更多数字,但我想知道你在我的情况下使用了什么.

解决方法:

您可以使用DECIMAL,它可能是存储负数的最佳数据类型.

Standard SQL requires that DECIMAL(5,2) be able to store any value

with five digits and two decimals, so values that can be stored in the

salary column range from -999.99 to 999.99

虽然在您的情况下您可以使用TINYINT(1),因为它需要1个字节的存储空间,其范围是-128到127.

在旁注:

M indicates the maximum display width for integer types. The maximum

display width is 255. Display width is unrelated to the range of

values a type can contain, as described in Section 11.2, “Numeric

Types”. For floating-point and fixed-point types, M is the total

number of digits that can be stored.

标签:mysql

来源: https://codeday.me/bug/20190708/1407198.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值