I wanna create a trigger like this:
create trigger trigofstu before insert on student
for each row
begin
    if new.sage <18 then
        set new.sage = 18 ;
    end if;
end;
but i got the error like this:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5 0.016 sec

byw i used mysqlWorkbench thanks!!!
I have couple remarks about your code:
Any way, if you interesting in trigger way you can use next:
DELIMITER $$
CREATE TRIGGER trigofstu BEFORE INSERT ON test
FOR EACH ROW
BEGIN
    SET new.sage = GREATEST(18, COALESCE(new.sage, 0)) ;
END;
$$
DELIMITER ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With