设置约束最小0和最大无穷大

时间:2022-06-01 19:35:36

In mySQL I would like to set a constraint to an int(11) type to have a minimum value of 0 and a maximum of infinity.

在mySQL中,我想设置一个int(11)类型的约束,使其最小值为0,最大值为无穷大。

How can I do this ?

我怎样才能做到这一点 ?

Something like

ALTER TABLE jake (
   CONSTRAINT jake_const CHECK (thefield BETWEEN 1 AND ? )
)

or , I dont know, like

或者,我不知道,喜欢

ALTER TABLE jake (
   CONSTRAINT jake_const CHECK (thefield GREATEST 0 )
)

Thanks

1 个解决方案

#1


1  

  1. Integer cannot store infinity
  2. 整数不能存储无穷大

  3. Check does not work in mysql atall: http://dev.mysql.com/doc/refman/5.7/en/create-table.html , The CHECK clause is parsed but ignored by all storage engines.
  4. 检查在mysql atall中不起作用:http://dev.mysql.com/doc/refman/5.7/en/create-table.html,CHECK子句被解析但被所有存储引擎忽略。

For this case you could make it unsigned. And that is all...

对于这种情况,你可以使它无符号。这就是全部......

#1


1  

  1. Integer cannot store infinity
  2. 整数不能存储无穷大

  3. Check does not work in mysql atall: http://dev.mysql.com/doc/refman/5.7/en/create-table.html , The CHECK clause is parsed but ignored by all storage engines.
  4. 检查在mysql atall中不起作用:http://dev.mysql.com/doc/refman/5.7/en/create-table.html,CHECK子句被解析但被所有存储引擎忽略。

For this case you could make it unsigned. And that is all...

对于这种情况,你可以使它无符号。这就是全部......