ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:413.44KB ,
资源ID:12349450      下载积分:6 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-12349450.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据库实验四数据更新与视图.docx)为本站会员(b****6)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

数据库实验四数据更新与视图.docx

1、数据库实验四数据更新与视图实验四 数据更新与视图北京师范大学珠海分校信息技术学院12计算机1班一、数据更新使用相应SQL语句,完成如下操作:(1) 根据订单信息更新order表中的payment(订单总金额)字段的值。update orderset order.payment = a.totalfrom (select orderid,sum(price*quantity)as total from book,orderbook where bookid=bid group by orderid )awhere order.oid=a.orderidselect oid,paymentfrom

2、 order(2) 新建图书订购情况统计表bookstas(包含图书编号、图书名称、图书类别、图书价格和订购册数,数据类型自定),并根据数据库的订单情况将社科类图书的订购情况插入表中。图书订购情况统计表bookstas表bsidbtitlebcategorybpriceordersell图书编号图书名称图书类别图书价格订购册数intvarchar(50)intfloatintPrimary keycreate table bookstas( bsid int primary key, btitle varchar(50) , bcategory int , bprice float, orde

3、rsell int );insertinto bookstas(bsid,btitle,bcategory,bprice,ordersell)select bid,title,category,price,sum(quantity)from orderbook,bookwhere category=2and bookid=bidgroup by bid,title,category,price;select bookstas.*from bookstas;(3) 新建用户订购统计表userstas(包含用户编号、用户名、订单数量、总金额,数据类型自定),并根据数据库的订单情况将活跃用户(正常使

4、用、锁定)的情况插入表中。uidunameordernumpricesum用户编号用户名订单数量总金额intvarchar(20)intfloatPrimary keycreate table userstas( uid int primary key, uname varchar(20) not null , ordernum int , pricesum float,);insertinto userstas(uid,uname,ordernum,pricesum)select distinct uid,name,count(user),sum(payment)from order,use

5、r,userstatewhere (usid=1 or usid=2) and user.state=usid and user.uid=order.usergroup by uid,name;select userstas.*from userstas;(4) 给用户表增加一字段level(等级),初始值为0,根据各用户订单总金额来给予评级(1:100200元,2:200300元,3:300元以上)。ALTER TABLE user ADD level int default 0;update userset level= (select (case when pricesum100 and

6、 pricesum200 and pricesum300 then 3 end) level from userstas where user.uid=userstas.uid)select user.*from user;(5) 用户102通过提交了一订单购买1001号图书1本,请问如何在数据库中完成上述操作?(假设订单号编号连续,要求完成订单信息、库存更新、订单总额及用户等级信息)。insert order values(2014008,102,4,0,2014-01-10 13:50:33);insert orderbook values(2014008,1001,1);update o

7、rderset payment=sumTotalfrom order a, (select orderid,sum(quantity*price) sumTotal from book,orderbook where bookid=bid group by orderid) bwhere a.oid=b.orderidselect order.*from orderupdate bookset stock=sumstockfrom book a,(select bid,title,category.category,price,(stock -sum(quantity) sumstockfro

8、m book,category,orderbookwhere book.category=category.cid and bookid=bid group by bid,title,category.category,price,stock) bwhere a.bid=b.bidselect book.*from bookupdate userset level= (select (case when pricesum100 and pricesum200 and pricesum300 then 3 end) level from userstas where user.uid=users

9、tas.uid)select user.*from user(6) 给数据中库存在100本以上的图书增加库存,其中社科类图书分别增加200本、理工类图书分别增加300本。update bookset stock=stock+200where stock100 and category =(select cid from category where cid=2)update bookset stock=stock+300where stock100 and category =(select cid from category where cid=1)select book.*from boo

10、k(7) 将数据库中处于锁定状态的用户的状态更改为正常使用,同时重新设定其密码为0000。update userset state=1,password=0000where state = (select usid from userstate where userstate=锁定)select user.*from user(8) 将数据库中订单状态为“未提交”的订单状态修改为“已提交”,同时给予该订单九折优惠。update orderset state=2,payment=payment*0.9where state =(select osid from orderstate where

11、orderstate=未提交)select order.*from order(9) 将数据库已经停用的用户及订单信息全部删除。delete from orderbookwhere orderid in (select orderid from orderbook,order,user,userstate where userstate=停用 and user.state=usid and uid=user and oid=orderid)select orderbook.*from orderbookdelete from orderwhere user in (select order.u

12、ser from order,user,userstate where userstate=停用 and user.state=usid and uid=user)select order.*from orderdelete from userwhere state in (select state from user,userstate where userstate=停用 and user.state=usid)select user.*from user二、视图使用相应SQL语句,完成如下操作:(1)创建视图View1,查看各订单的订单号、下单用户、订单总金额和订单状态。create v

13、iew view1asselect oid,user,payment,statefrom order(2)创建视图View2,查看各图书的编号、作者、名称、出版社、价格、订购册数。create view view2asselect bid,title,author,press,price,bookstas.ordersellfrom bookstas,bookwhere bsid=bid(3)创建视图View4,查看社科类图书的基本情况,并保证以后对该视图的修改都要满足专业为“社科类图书”这个条件。create view view4as select bid,title,author,pres

14、s,price,book.category,stockfrom book,categorywhere category.category=社会科学类 and cid=book.categorywith check option(4)通过View1,查看订单总额在100元以上(含100元)且状态为已完成的订单号、下单用户、订单总金额。select oid,user,paymentfrom view1,orderstatewhere payment=100 and state=osid and orderstate=已完成(5)通过视图View2,查看订购册数在平均值以上的图书编号、作者、名称、出版社、价格、订购册数,并按订购册数降序排列。select bid,title,author,press,price,ordersellfrom view2 where ordersell (select AVG(ordersell)from view2)(6)通过视图View4,将库存在200本以上的图书的库存分别减少50本。update view4set stock=stock-50where stock200(7)删除视图View1.drop view view1

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2