- 1. 创建一个触发器,当一本书被还回时,从LOAN表中删除相应的借阅记录,将该学生借阅这本书记录添加到LoadHist表中;并检查是否有用户在等待预约这本书,如有则将这本书的借阅状况修改为 已经预约;按照预约的日期先后,先向预约在前的用户发送信息,并将状态改为T。
- 2. 创建一个触发器,当借书成功,则检索是否有这个用户的预约该书的记录,如果有,则删除相应的预约记录。
- 3. 创建一个触发器,当读者还书时,如果超期罚款, 通过触发器在收费表中添加一条收费记录。
- 1.create trigger umgsai ON
- loan --在Goods表中创建触发器
- for delete
- As --事件触发后所要做的事情
- begin
- declare @借阅证号 char(20);
- declare @借阅证号1 char(20)
- declare @书号 char(20);
- declare @借阅日期 char(20);
- declare @归还日期 char(20);
- declare @ISBN char(20);
- select @借阅证号=L.借阅证号 from deleted L;
- select @书号=L.书号 from deleted L;
- select @借阅日期=L.借阅日期 from deleted L;
- select @ISBN =(select ISBN from books where 书号='@书号')
- set @归还日期=getdate()
- begin
- insert into loanhist (借阅证号,书号,借阅日期,归还日期)values(@借阅证号,@书号,@借阅日期,@归还日期);
- select @借阅证号1=(select top 1 借阅证号 from reservation where ISBN=@ISBN )
- update reservation set 状态='T' where 借阅证号=@借阅证号1
- end;
- end;
- 2.
- create trigger umgsai1 ON
- loan --在Goods表中创建触发器
- for insert
- As --事件触发后所要做的事情
- begin
- declare @借阅证号 char(20);
- declare @书号 char(20);
- declare @ISBN char(20);
- select @借阅证号=L.借阅证号 from inserted L
- select @书号=L.书号 from inserted L
- select @ISBN=(select ISBN from books where 书号=@书号)
- begin
- delete from reservation where 借阅证号=@借阅证号 and ISBN= @ISBN
- end;
- end;
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/702562