ÍøÉÏÊé³ÇÐÅϢϵͳÊý¾Ý¿â¿Î³ÌÉè¼Æ ÏÂÔØ±¾ÎÄ

insertinto bookdetail values('kp','10010',' ') insertinto bookdetail values('sw','10011',' ') insertinto bookdetail values('kp','10012',' ')

insertinto orders values('0001','0001','ÕÅÓî','±±¾©','ɽÄDZß',15)

insertinto orderdetail values( 6501001,'0001',2015/12/30)

altertable orderdetail withnocheck

addconstraint FK_OD_O FOREIGNKEY(orderdetailno)references orders(orderdetailno) ondeletecascade

--ÈçºÎÈ·¶¨orderÀïµÄÃû×Ö±ØÐëÔÚuserinfoÖдæÔÚ altertable orders withnocheck

addconstraint FK_u_o_update FOREIGNKEY(userno)references userinfo(userno) onupdatecascade

33

--Íâ¼ü

altertable bookdetail withnocheck addconstraint book(bookno) ondeletecascade --Óû§¶©µ¥¼¶ÁªÉ¾³ý´¥·¢Æ÷ createtrigger tr_u_o on userinfo fordelete asdeclare @uname_del char(20) select @uname_del= uname from deleted deletefrom orders where uname=@uname_del go

--¶©µ¥ºÍ¶©µ¥ÏêÇéµÄ¼¶ÁªÉ¾³ý´¥·¢Æ÷ createtrigger tr_order_detail on orders fordelete as

declare @orderno_del char(10)

select @orderno_del= orderno from deleted deletefrom orders where orderno=@orderno_del go

--±íÖµº¯Êý

34

FK_BD_B FOREIGNKEY(bookno)references

createfunction U_Orders_fun(@uname_in char(20)) returnstable as

return (select userinfo.userno ±àºÅ,userinfo.uname ÐÕÃû,

userinfo.address µØÖ·,bname ÊéÃû,price ¼Û¸ñ,orderno ¶©µ¥ºÅ

from userinfo,orders,orderdetail where userinfo.uname=orders.uname and

orders.orderdetailno=orderdetail.orderdetailno and userinfo.uname=@uname_in) go

select*from U_Orders_fun('ÍõÓî')

--¹ºÊéÇé¿ö±íÖµº¯Êý

createfunction B_Orders_fun(@bname_in varchar(20)) returnstable as

return (select book.bname ÊéÃû,book.price ¼Û¸ñ,orderno ¶©µ¥ºÅ

from book,orders

35

where book.bname=orders.bname and book.bname=@bname_in) go

select*from B_Orders_fun('ÑòƤ¾í')

--Óû§ÂòÊéµÄÏêϸÇé¿öÊÓͼ

createview userifro_o(uname,address,orderno,bname) as

select userinfo.uname, userinfo.address,orderno,bname from userinfo,orders

where orders.uname=userinfo.uname and orderno isnotnull

--Êé¼®Çé¿öµÄÊÓͼ

createview book_ca( bname,pdate,exist ,remark) as

selectdistinct bname,pdate,exist,remark from book,catagory,bookdetail

where book.bookno=bookdetail.bookno and bookdetail.crono=catagory.crono

--Êý¾Ý¿â±¸·Ý

36