sql - How check if the sum of the values of two columns, in the same row have exactly 100 as result in mysql -


i have problem in mysql (phpmyadmin).. should want check if values of 2 columns 100… example have table

| blablabla |         blablabla | value1 | value2 |   

and user want add values(bla, bla, 20, 30).. 20 , 30 can't added in table because 20+30<>100.. code is:

alter table `partita` check (`100` = (select (`possesso_palla_casa`+`possesso_palla_ospite`)                        `partita`))   

but naturally wrong.. how can do? thank all!!!

as commented mysql doesn't support check constraint. per mysql documentation says:

the check clause parsed ignored storage engines

you should rather use before insert trigger alternative below

delimiter // create trigger sumcheck_before_insert before insert    on bla_table each row  begin if (new.value1 + new.value2 <> 100)       signal sqlstate '45000' set message_text = 'can not insert data'; end if    end; // delimiter ; 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -