CREATE TRIGGER bookhavelog ON dbo.user_book FOR DELETE AS declare @bookISBN varchar(50) select @bookISBN=book_ISBN from deleted if exists(select * from user_logBook where logb_book_ISBN=@bookISBN and logb_backdate is null) begin rollback return end 用户续借图书的存储过程 利用存储过程实现用户续借图书的逻辑操作,根据用户的当前信息判断其是否有续借的权限,并把处理结果输出到临时表中去。
CREATE PROCEDURE user_renew_book @xxxparm int AS
CREATE TABLE ##temp(statement varchar(50)) DECLARE @username varchar(50) SET @username=(select logb_cons_username from user_logBook where ID=@xxxparm) IF @username is null BEGIN INSERT INTO ##temp VALUES ('The ID is not EXIST') RETURN END DECLARE @timelimit int SET @timelimit=(select logb_timelimit from user_logBook where ID=@xxxparm) DECLARE @renewday int SET @renewday=(select cons_maxday from user_consumer where cons_username=@username) DECLARE @maxrenew int SET @maxrenew=(select cons_maxrenew from user_consumer where cons_username=@username) IF (@renewday*@maxrenew)>=@timelimit BEGIN update user_logBook set logb_timelimit=logb_timelimit+@renewday where ID=@xxxparm --update user_consumer set cons_maxrenews=cons_maxrenews-1 where cons_username=@username INSERT INTO ##temp VALUES ('renew successful') RETURN END ELSE BEGIN INSERT INTO ##temp VALUES ('You are not allowed to renew the book') RETURN END GO 到期催还表的视图 利用DATEDIFF,DATEADD,CAST,GETDATE等函数从借书记录表中计算出到期的记录,然后根据此记录找出相应的读者信息,在网页上以email形式催还。
CREATE VIEW dbo.deadline AS SELECT TOP 100 PERCENT dbo.user_logBook.logb_cons_username, dbo.user_logBook.logb_outdate, DATEADD([day], dbo.user_logBook.logb_timelimit, CAST(dbo.user_logBook.logb_outdate AS datetime)) AS deadline_date, GETDATE() AS now_date, dbo.user_consumer.cons_name, dbo.user_consumer.cons_kind, dbo.user_consumer.cons_rank, dbo.user_consumer.cons_email, dbo.user_consumer.cons_maxrenew, dbo.user_consumer.cons_maxbook, dbo.user_logBook.logb_book_ISBN, dbo.user_book.book_name, dbo.user_book.book_kind, dbo.user_book.book_storage, dbo.user_book.book_rank, dbo.user_logBook.logb_timelimit FROM dbo.user_logBook INNER JOIN dbo.user_consumer ON dbo.user_logBook.logb_cons_username = dbo.user_consumer.cons_username INNER JOIN dbo.user_book ON dbo.user_logBook.logb_book_ISBN = dbo.user_book.book_ISBN WHERE (DATEDIFF([day], DATEADD([day], dbo.user_logBook.logb_timelimit, CAST(dbo.user_logBook.logb_outdate AS datetime)), GETDATE()) >= 0) AND (dbo.user_logBook.logb_backdate IS NULL) ORDER BY dbo.user_logBook.logb_cons_username DESC 3.2 数据链接层设计
findSearcher实现模糊查找的代码: select object(p) from UserBook as p where p.bookName like concat(concat('%',?1),'%') or p.bookAuthor like ?1 or p.bookKind like ?1 or p.bookPublish like ?1 or p.bookAbstract like ?1 or p.bookISBN like concat(concat('%',?1),'%') or p.bookRemark like ?1 UserConsumer Entity Bean设计
findSearcher实现模糊查找的代码: select object(p) from UserConsumer as p where p.consUsername like concat(concat('%',?1),'%') or p.consSerial like ?1 or p.consName like concat(concat('%',?1),'%') or p.consRemark like ?1 or p.consEmail like ?1 UserLogBook Entity Bean设计
FindLogByDay通过模糊匹配得到一组最终记录时间的代码: select object(p) from UserLogBook as p where ( p.logbBackdate is null and p.logbOutdate like concat(concat('%',?1),'%') ) or ( p.logbBackdate is not null and p.logbBackdate like concat(concat('%',?1),'%') ) 3.3 数据逻辑层设计