Check inserted value with a trigger : Before Trigger « Trigger « SQL / MySQL






Check inserted value with a trigger

      


create table test(
  percent decimal

);

delimiter $$

CREATE TRIGGER test_before_insert
BEFORE INSERT ON test FOR EACH ROW
BEGIN
    IF NEW.percent < 0.0 OR NEW.percent > 1.0 THEN
        SET NEW.percent = NULL;
    END IF;
END$$

delimiter ;

drop trigger test_before_insert;
drop table test;

   
    
    
    
    
    
  








Related examples in the same category

1.Before insert trigger
2.Create a 'Before update trigger'
3.Update table in a before update trigger
4.Change the NEW value based on the input in a BEFORE INSERT trigger
5.Change the NEW value based on the input in the BEFORE UPDATE trigger
6.The two triggers to ensure valid data.