工具推荐
任务描述
创建一个触发器tri_loan,当借书成功,修改该书的状态为“1”(代表已经借出),并检索是否有这个用户的预约该书的记录,如果有,则删除相应的预约记录
/*2. 创建一个触发器tri_loan,当借书成功,修改该书的状态为“1”(代表已经借出),
并检索是否有这个用户的预约该书的记录,如果有,则删除相应的预约记录*/
use library;
drop trigger if exists tri_loan;
delimiter //
######### Begin #########
create trigger tri_loan
after insert on Loan
for each row
begin
update Books set bstatus=1 where Books.bookNo=new.bookNo;
if exists(select * from Reservation,Books where Reservation.ISBN=Books.ISBN and Books.bookNo=new.bookNo) then
delete from Reservation where Reservation.loanNo=new.loanNo;
end if;
end;//
######### End ##########
delimiter ;