Search code examples
mysqldefault

MySql : set column value by using operators


I have table in MySql database want to limit some column value,

is it possible to make a column in table to take specified value such as (value <= 3) ?


Solution

  • you need to use a constraint named check which will be defined on table creation and check the value before insert .

    CREATE TABLE table_name (          
        value INT ,
        CHECK(value <= 3)
    )