MySQL 布尔值“tinyint(1)"保持值高达 127?

编程入门 行业动态 更新时间:2024-10-21 15:36:48
本文介绍了MySQL 布尔值“tinyint(1)"保持值高达 127?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想为某件商品是否有货设置一个真/假字段.

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?

本文发布于:2023-11-17 07:04:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔值   MySQL   tinyint   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!