簡答三
begin transaction
declare @errorsum int
declare @rid varchar(50)
declare @bid varchar(50)
select @rid=rid from reader where rname='張無忌'
select @bid=bid from book where bname='深入。net平台和c#程式設計'
set @errorsum=0
insert into borrow(rid,bid)values (@rid,@bid)
set @errorsum=@errorsum+@@error
update book set bcount=bcount-1 where bname=' 深入。net平台和c#程式設計'
set @errorsum=@errorsum+@@error
update reader set lendnum=lendnum+1 where rname='張無忌'
set @errorsum=@errorsum+@@error
if @errorsum<>0
rollback transaction
else
commit transactiongo四
begin transaction
declare @errorsum int
declare @rid varchar(50)
declare @bid varchar(50)
select @rid=rid from reader where rname='劉冰冰'
select @bid=bid from book where bname='西遊記'
set @errorsum=0
insert into penalty(rid,bid,ptype,amount) values(@rid,@bid,'1',5.6)
set @errorsum=@errorsum+@@error
update borrow set returndate=getdate() where bid=@bid
set @errorsum=@errorsum+@@error
update reader set lendnum=lendnum-1 where rname='劉冰冰'
set @errorsum=@errorsum+@@error
update book set bcount=bcount+1 where bid=@bid
set @errorsum=@errorsum+@@error
if @errorsum<>0
rollback transaction
else
commit transactiongo五
use library
go--建立索引
if exists (select * from sysindexes
where name = 'ix_book_bookname')
drop index book.ix_book_bookname --刪除索引
/*--筆試列建立非聚集索引:填充因子為30%--*/
create index ix_book_bookname
on book(bname)
with fillfactor = 30
go--建立管理員檢視
if exists (select * from sysobjects where name='view_borrow')
drop view view_borrow
gocreate view view_borrow
as select 圖書名稱=book.bname,到期時間=borrow.willdate,讀者姓名=book.bname
from borrow,book
with (index = ix_book_bookname)
where book.bid=borrow.bid
--order by borrow.willdate
goselect * from view_borrow
--建立讀者檢視
if exists(select *from sysobjects where name='view_book')
drop view view_book
gocreate view view_book
as select 圖書名稱=bname,圖書總量=bcount,可借閱量=bcount-(
select count(*) from borrow where returndate is null and borrow.bid = book.bid
) from book
with (index = ix_book_bookname)
goselect * from view_book
第六章課後簡答題
1.借閱事務 事務操作借書 begin transaction declare errorsum int declare rid varchar 50 declare bid varchar 50 select rid rid from reader where rname 張無忌 select b...
第六章解答題
begin transaction declare errorsum int declare rid varchar 50 declare bid varchar 50 select rid rid from reader where rname 張無忌 select bid bid from bo...
簡答題總結(六)
1.請列出c 中幾種迴圈的方法,並指出他們的不同 1 hile迴圈 通常用於不確定的迴圈次數時去使用它 2 do while迴圈 功能上和while基本類似,不同之處它保證了迴圈至少執行一次 3 for 迴圈 主要用於迴圈次數固定的迴圈 4 foreach迴圈 是一種十分高效的迴圈,主要用來遍歷ie...