gpt4 book ai didi

mySql 数据库 - ID auto_increment : what are the risks of it?

转载 作者:搜寻专家 更新时间:2023-10-30 22:12:04 25 4
gpt4 key购买 nike

我是数据库的新手,我希望您能回答我的问题:我有一个带有 ID 的表,该 ID 是主键,而不是 null 和自动递增。它的数据类型是 int,限制为 50 位。该表将不断接收新行,所以我想知道由于数字限制而离开原样是否危险以及如何解决此问题。我知道这听起来可能很傻,但我真的开始了解数据库了。

最佳答案

我不认为你会面临任何危险。如果您已将主键设置为最多包含 50 位数字,那么我认为这没有任何问题,因为

9999999..........50 times...99 will be a large number

但是我不确定您使用的是哪种数据类型。因为就 BIGINT 而言,BIGINT 始终为 8 个字节,并且可以存储 -9223372036854775808 到 9223372036854775807(有符号)或 0 到 18446744073709551615(无符号)。这离 50 位数字还差得很远,但是是的,这是一个很大的数字,很难达到。

旁注:

[...] 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. ...

The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters.

关于mySql 数据库 - ID auto_increment : what are the risks of it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25270484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com