第六章課後簡答題

2021-07-27 10:30:27 字數 2902 閱讀 8184

1.借閱事務

*事務操作借書

*/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 transaction

go2.罰款事務 /*

*事務操作借書

*/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 transaction

go3.檢視

1.--建立索引 

2.if exists (select * from sysindexes  

3.          where name = 'ix_book_bookname') 

4.   drop index book.ix_book_bookname  --刪除索引 

5./*--筆試列建立非聚集索引:填充因子為30%--*/ 

6.create index ix_book_bookname 

7.   on book(bname) 

8.       with fillfactor = 30 

9.go 

10. 

11.--建立管理員檢視 

12.if exists (select  * from sysobjects  where  name='view_borrow') 

13.    drop view view_borrow 

14.go 

15.create view view_borrow  

16.    as 

17.        select   圖書名稱=book.bname,到期時間=borrow.willdate,讀者姓名=book.bname  

18.        from borrow,book  

19.        with (index = ix_book_bookname) 

20.        where  book.bid=borrow.bid  

21.        --order by borrow.willdate 

22.go 

23. 

24.select * from view_borrow 

25. 

26. 

27.--建立讀者檢視 

28.if exists(select  *from sysobjects  where  name='view_book') 

29.    drop view view_book 

30.    go 

31.create view view_book 

32.    as  

33.        select  圖書名稱=bname,圖書總量=bcount,可借閱量=bcount-( 

34.          select count(*) from borrow where returndate is null and borrow.bid = book.bid 

35.        ) from book  

36.        with (index = ix_book_bookname) 

37.go 

38. 

39.select * from view_book 

SQL 第六章簡答題

簡答三 begin transaction declare errorsum int declare rid varchar 50 declare bid varchar 50 select rid rid from reader where rname 張無忌 select bid bid fro...

第六章解答題

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.this和super各有幾種用法?1.子類的建構函式如果要引用super的話,必須把super放在函式的首位。2.子類中的同名成員變數或方法隱藏了父類的成員變數或方法,需要用到super。3.用super直接傳遞引數。2.子類物件例項化的具體過程是什麼?1.子類在構造物件時候,必須訪問父類的建構...