It is necessary to limit the values ​​entered into the database. Tried to make through ALTER TABLE tablename ADD CHECK (columnname > 10) . But either I'm doing something wrong, or this feature is not supported in the InnoDB MySql database. There are two options left: limit the trigger, or just make a separate table from a single attribute, and refer from the child table to the created parent. Which option is better? I do not like triggers, because if anything, I need to delete the trigger and write again, and the values ​​I have are a finite set (4-5 values).

  • Yes, MySQL does not support such restrictions in principle, regardless of the table engine. Only create allows "for compatibility". I wonder how you will create records in the variant with the second table, you initially put all possible numbers from 10 to infinity in it :) if on the fly you create records in it then who will not allow to put the number <10 in it? there is a trigger ... - Mike
  • Of course, to limit the numerical values, only the trigger remains. But I mentioned that I have values ​​from a finite set (5-6 variants, a string value). Creating a trigger is not a hunt, because if some new record appears, you have to delete the trigger, then add it. - van9petryk
  • Yes, I did not finish reading. inattentive. When I use multiple values, I always prefer to make a table, even instead of the check task (I work with another DBMS), just in case. Only fields like 'Y', 'N' I do on check and then once I had to change such a check because besides YN the third value appeared :) - Mike

1 answer 1

Reply from comments from Mike

Yes, MySQL does not support such restrictions in principle, regardless of the table engine. Only create allows "for compatibility".

Therefore, it remains to either trigger, or create a separate table, saving either 'Y' or 'N' as the value.