问题描述
我想为某件商品是否有货设置一个真/假字段.
I wanted to make a true/false field for if an item is in stock.
我想将其设置为布尔值(转换为 tinyint(1)
),1 表示有货,0 表示没有库存.
I wanted to set it to Boolean ( which gets converted to tinyint(1)
), 1 for in stock, 0 for not in stock.
我从供应商那里获取信息,所以我想,如果他们通过了有多少库存怎么办?"
I am getting feeds from vendors, so I thought to myself, "What if they pass how many are instock?"
所以我想知道如果我插入一个大于 1 的数字会发生什么.我以为它会默认为 1.
So I wondered if I inserted a number higher than 1 what would happen. I assumed it would default to 1.
令我惊讶的是,它允许我保存不超过 127 的任何数字,超过默认值 127 的任何数字.
To my surprise it will allow me to hold any number up to 127, anything over defaults to 127.
谁能解释一下原因?
推荐答案
有符号的TINYINT
数据类型可以存储-128到127之间的整数值.
The signed TINYINT
data type can store integer values between -128 and 127.
但是,TINYINT(1)
不会更改它可以存储的最小值或最大值.它只是说显示当该类型的值作为输出打印时只显示一个数字.
However, TINYINT(1)
does not change the minimum or maximum value it can store. It just says to display only one digit when values of that type are printed as output.
这篇关于MySQL 布尔值“tinyint(1)"保持值高达 127?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!