sql - What should I use triggers or constraints? -
in sql developer created table
bill (id,nr,cost,days,total -all integers)
and need create constraint (or trigger -what best) act
if nr > 10 total = total -5 (total = nr * cost * days ). create or replace trigger discount after insert or update on bill update bill set total = nr * cost * nr - 5; when (nr_slide > 10 )
can use update inside triggers?
constraint can prevent putting wrong value table. if use constraint, need calculate correct value total , insert table, otherwise no rows inserted. means need trigger.
create or replace trigger discount after insert or update on bill each row -- added here begin if :new.nr > 10 :new.total = :new.nr * :new.cost * :new.days - 5; end if; end;
if educational project - no problem (of course, problem - quite bad example education). in applications real life use advise of ash burlaczenko.
Comments
Post a Comment