2016数据库实验完整版.doc_第1页
2016数据库实验完整版.doc_第2页
2016数据库实验完整版.doc_第3页
2016数据库实验完整版.doc_第4页
2016数据库实验完整版.doc_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实 验 报 告(1 6 / 1 7 学年 第 一 学期)课程名称数据库系统与设计实验名称数据库系统程序设计与分析实验时间1 6年12月15/22日指导单位计算机学院、软件学院指导教师毛燕琴学生姓名班级学号B140205 学院(系)电子科学与工程学院专 业电磁场与无线技术实 验 报 告实验名称数据库系统程序设计与分析指导教师毛燕琴实验类型上机实验学时8实验时间12.15 6-9节12.22 6-9节一、 实验目的和要求(1)掌握数据库系统创建和数据添加的程序设计方法(2)掌握采用SQL编程语言实现关系数据库查询的程序设计方法要求独立完成实验方案的设计、数据库的构建、数据录入、SQL程序的编制、调试和运行;要求独立完成实验报告的编写。 二、 实验环境(实验设备)硬件:微机软件:SQL Server或者MySQL三、 实验原理及内容实验1、利用教材习题 2.3.1给出的关系模式和习题2.4.1给出的数据,建立包括Product、PC、Laptop、Printer四个关系模式的关系数据库,并且录入四个关系的样例数据。实验2、按照教材习题6.2.2要求,利用实验1已经建立的关系数据库,编写并执行查询语句,得出查询结果。实验3、按照教材习题 6.3.1要求,使用子查询编写查询语句,对在实验1中建立的关系数据库进行查询,并且记录查询结果。实验4、按照教材习题 6.4.6要求,编写查询语句,对在实验1中建立的关系数据库进行查询,并且记录查询结果。参考教材数据库系统基础教程(第三版)中译本,Jeffery D. Ullman, Jennifer Widon著,岳丽华,金培权,万寿红等译. 北京:机械工业出版社,2011.实 验 报 告四、 实验方案、过程和结果(包括SQL语句或执行过程的截图以及执行结果的截图)软件版本:SQL Server2016Microsoft SQL Server Management Studio(SSMS)软件界面:实验1、利用教材习题 2.3.1给出的关系模式和习题2.4.1给出的数据,建立包括Product、PC、Laptop、Printer四个关系模式的关系数据库,并且录入四个关系的样例数据。表总览:PC数据类型:Laptop数据类型:Printer数据类型:Product数据类型:关系PC数据:关系Laptop数据:关系Printer数据:关系Product数据:实验2、按照教材习题6.2.2要求,利用实验1已经建立的关系数据库,编写并执行查询语句,得出查询结果。习题6.2.2Product(maker,model,type)PC(model,speed,ram,hd,price)Laptop(model,speed,ram,hd,screen,price)Printer(model,color,type,price)查询步骤:然后a) 查询硬盘容量至少30G的笔记本电脑制造商及该电脑的速度。查询语句:selectmaker,speedfromProduct,Laptopwherehd30ANDLaptop.model=Product.model查询结果: b) 查询制造商B生产的任意类型的所有产品的型号和价格。查询语句:selectProduct.model,pricefromProduct,PCwhereProduct.model=PC.modelANDmaker=BunionselectProduct.model,pricefromProduct,LaptopwhereProduct.model=Laptop.modelANDmaker=BunionselectProduct.model,pricefromProduct,PrinterwhereProduct.model=Printer.modelANDmaker=B查询结果:c) 查询卖笔记本电脑不卖PC的厂商。查询语句:select maker from product where type=laptopexceptselect maker from product where type=pc查询结果:d) 查询出现在两种或两种以上PC中硬盘的大小。查询语句:select distinct pc1.hd from PC pc1,PC pc2 where pc1.modelpc2.model and pc1.hd=pc2.hd查询结果:e) 查询每对具有相同速度和RAM容量的PC型号。每一对只能列出一次,例如若(i,j)已被列出,则(j,i)就不能再被列出。查询语句:select pc1.model,pc1.speed,pc1.ram,pc2.ram,pc2.speed,pc2.modelfrom pc as pc1,pc as pc2where pc1.speed=pc2.speedand pc1.ram=pc2.ramand pc1.modelpc2.model查询结果:f) 查询生产至少两种速度至少3.0的电脑(PC或笔记本电脑)的厂商。查询语句:select M.makerfrom (select maker, R.model from PC P, Product R where Speed =3.0 and P.model=R.modelunion select maker, R.model from laptop L, Product R where speed =3.0 and L.model=R.model)MGroup BY M.makerhaving count(M.model) =2查询结果:实验3、按照教材习题 6.3.1要求,使用子查询编写查询语句,对在实验1中建立的关系数据库进行查询,并且记录查询结果。基于习题2.4.1的数据库模式写出后面的查询。Product(maker,model,type)PC(model,speed,ram,hd,price)Laptop(model,speed,ram,hd,screen,price)Printer(model,color,type,price)每题的答案应当至少使用一个子查询,并且要求使用两种不同的方法写出每个子查询。a) 找出速度在3.0以上的PC制造商。查询语句:语句1:select distinct makerfrom productwhere model in(select modelfrom pcwhere speed3.0)语句2:.select distinct makerfrom productwhere exists(select *from pcwhere speed3.0and model=product.model)查询结果:b) 找出价格最高的打印机。查询语句:语句1:select P1.modelfrom Printer P1where P1.price = ALL (select P2.price from Printer P2 ) ;语句2:select P1.modelfrom Printer P1where P1.price IN(select MAX(P2.price)from Printer P2);查询结果:c) 找出速度比任何一台PC都慢的笔记本电脑。查询语句:语句1:select L.modelfrom Laptop Lwhere L.speed=L.speed );查询结果:d)找出价格最高的产品的型号查询语句:语句1:select modelfrom (select model,price from pc union select model,price from laptop unionselect model,price from printer)M1where M1.price=all(select price frompc union select price from laptopunionselect price from printer);语句2:select modelfrom (select model,price from PC union select model,price from laptop union select model,price from printer)M1 where M1.price IN (select MAX(price) from (select price from PC union select price from laptop union select price from Printer)M2 );查询结果:e) 找出价格最低的彩色打印机的制造商。查询语句:语句1:select R.makerfrom product R,printer Twhere R.model=T.modeland T.price=all (select P1.speed from Product R1,PC P1 where R1.model=P1.model and P1.ram IN (select MIN(ram) from PC) ); 语句2:select R1.maker from Product R1, PC P1 WHERE R1.model=P1.model and P1.ram=(select MIN(ram) from PC) and P1.speed IN (select MAX(P1.speed) from Product R1, PC P1 where R1.model=P1.model and P1.ram IN (select MIN(ram) from PC) );查询结果:实验4、按照教材习题 6.4.6要求,编写查询语句,对在实验1中建立的关系数据库进行查询,并且记录查询结果。a) 查询PC的平均速度。查询语句:select avg(speed) as 平均速度from pc;查询结果:b)查询价格在$1000以上笔记本电脑的平均速度。查询语句:select avg(speed) as 平均速度from laptopwhere price1000查询结果:c)查询厂商“A”生产PC的平均价格。查询语句:select avg(price) as 平均价格from product,pcwhere product.model=pc.modeland maker=A查询结果:d)查询厂商“D”生产的PC和笔记本电脑的平均价格。查询语句:select avg(price) as 平均价格from(select price from product,pc where product.model=pc.model and maker=D)union(select price from product,laptop where product.model=laptop.model and maker=D) as sprice查询结果:e)查询不同速度PC的平均价格。查询语句:select speed,avg(price) as平均价格from pcgroup by speed查询结果:f)查询各个厂商生产笔记本电脑的平均屏幕尺寸。查询语句:select maker,avg(screen) as avgscreenfrom product,laptopwhere product.model=laptop.modelgroup by maker查询结果:g)查询至少生产3种不同型号PC的制造商。查询语句:select maker,count(pc.model) as 型号数from product,pcwhere product.model=pc.modelgroup by makerhaving count(pc.model)=3查询结果:h)查询每个厂商生产PC的最高价格。查询语句:select maker,max(price) as 最高价格from product,pcwhere product.model=pc.modelgroup by maker查询结果:i)查询每种速度高于2.0PC的平均价格。查询语句:select speed,avg(price) as 平均价格from pcwhere speed2.0group by speed查询结果:j)查询所有生产打印机的厂商生产PC硬盘容量的平均大小查询语句:select maker,avg(hd) as 硬盘容量平均大小from product,pcwhere product.model=pc.modeland maker in(select makerfrom productwhere type=printer)group by maker查询结果:实 验 报 告五、实验小结(包括问题和解决方法、心得体会、意见与建议等) 首先软件的安装比较繁琐,SQL Server2016的使用需要搭配软件Microsoft SQL Server Management Studio(SSMS)才能使用。安装完软件后,本地服务器的连接也出现了一些问题,有的时候关机之后或者使用360安全管家之后就无法继续使用,经过

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论