1

I want to set a value range to a column of a table.

Example For the decimal decimal, This decimal column should allow to insert or update the value between 0 to 30.

Thanks in advance...!

Gnanendra
  • 173
  • 1
  • 5
  • 11
  • Does this answer your question? [Want to restrict the value of a MySQL field to specific range (Decimal values)](https://stackoverflow.com/questions/9575604/want-to-restrict-the-value-of-a-mysql-field-to-specific-range-decimal-values) – Ivar Nov 04 '20 at 08:57

2 Answers2

2

As MySQL still doesn't support check constraints, the only way to do this in MySQL is a trigger (for update and insert) that checks the new value of the column and throws an error if the value is outside the valid range.

1

look for ENUM and SET Constraints http://dev.mysql.com/doc/refman/5.6/en/constraint-enum.html

Rabi Panda
  • 73
  • 8
  • How would you define an enum that contains all possible decimal values between 0 and 30? That's an infinite number of elements. And sets can only contain character values, no numbers if I'm not mistaken –  May 11 '11 at 06:44