sql - MySQL BEFORE UPDATE TRIGGER giving ERROR -
i've been working on trigger mysql couple hours now, , can't figure out what's wrong.
here table structure:
create table if not exists `rentalvideo` ( `orderid` int(11) not null, `videobarcode` int(11) not null, `rentalreturned` tinyint(1) not null default '0', primary key (`orderid`,`videobarcode`), key `rentalvideo_videobarcode_fk` (`videobarcode`) )
here's sample data:
insert `rentalvideo` (`orderid`, `videobarcode`, `rentalreturned`) values (1, 223823, 0), (1, 447956, 0), (3, 705481, 0), (4, 988908, 0), (5, 143375, 0);
here's trigger that's not working:
create trigger `rent_five_videos_max` before insert on `bollywoo_video`.`rentalvideo` each row begin -- variable declarations declare vrentedvideos int; declare vcustomer int; -- trigger code select rentalorder.custid rentalorder rentalorder.orderid = new.orderid vcustomer; select count(*) rentalorder, rentalvideo rentalorder.custid = vcustomer , rentalvideo.rentalreturned = 0 , rentalorder.orderid = rentalvideo.videoid vrentedvideos; if vrentedvideos >= 5 call raise_application_error(-2000, 'cannot checkout more 5 videos'); end if; end
and last not least, error i'm getting:
error sql query: create trigger `rent_five_videos_max` before insert on `bollywoo_video`.`rentalvideo` each row begin -- variable declarations declare vrentedvideos int; mysql said: documentation #1064 - have error in sql syntax; check manual corresponds mariadb server version right syntax use near '' @ line 6
the error appears occurring right before declare vrentedvideos int;
remove semicolon , try this
delimiter $$ create trigger `rent_five_videos_max` before insert on `bollywoo_video`.`rentalvideo` each row begin ... end$$ delimiter ;
Comments
Post a Comment