数据库实验报告B09050221.docx

上传人:b****6 文档编号:16735426 上传时间:2023-07-16 格式:DOCX 页数:15 大小:215.37KB
下载 相关 举报
数据库实验报告B09050221.docx_第1页
第1页 / 共15页
数据库实验报告B09050221.docx_第2页
第2页 / 共15页
数据库实验报告B09050221.docx_第3页
第3页 / 共15页
数据库实验报告B09050221.docx_第4页
第4页 / 共15页
数据库实验报告B09050221.docx_第5页
第5页 / 共15页
数据库实验报告B09050221.docx_第6页
第6页 / 共15页
数据库实验报告B09050221.docx_第7页
第7页 / 共15页
数据库实验报告B09050221.docx_第8页
第8页 / 共15页
数据库实验报告B09050221.docx_第9页
第9页 / 共15页
数据库实验报告B09050221.docx_第10页
第10页 / 共15页
数据库实验报告B09050221.docx_第11页
第11页 / 共15页
数据库实验报告B09050221.docx_第12页
第12页 / 共15页
数据库实验报告B09050221.docx_第13页
第13页 / 共15页
数据库实验报告B09050221.docx_第14页
第14页 / 共15页
数据库实验报告B09050221.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

数据库实验报告B09050221.docx

《数据库实验报告B09050221.docx》由会员分享,可在线阅读,更多相关《数据库实验报告B09050221.docx(15页珍藏版)》请在冰点文库上搜索。

数据库实验报告B09050221.docx

数据库实验报告B09050221

 

实验报告

(2010/2011学年第二学期)

 

课程名称

数 据 库 系 统与设计

实验名称

数据库系统程序设计与分析

实验时间

2011

5

10/17

指导单位

计算机学院/软件学院

指导教师

沈苏彬、李莉

 

学生姓名

杨亚运

班级学号

B09050226

学院(系)

计算机学院

专业

软件工程(NIIT)

 

实验报告

实验名称

数据库系统程序设计与分析

指导教师

沈苏彬、李莉

实验类型

上机

实验学时

6

实验时间

2011.5.10/17

一、实验目的和要求

(1)掌握数据库系统创建和数据添加的程序设计方法

(2)掌握采用数据库查阅语言SQL实现关系数据库查询的程序设计方法

(3)比较核心SQL与完全SQL在功能和性能方面的差异

二、实验环境(实验设备)

硬件:

计算机(XP)

软件:

SQLServer2005

三、实验原理及内容

3.1利用教材第127页习题5.2.1给出的关系模式和数据,建立包括Product、PC、Laptop、Printer四个关系模式的关系数据库,并且录入给出的关系数据库数据。

3.2按照教材第164页习题6.2.2要求,编制查询语句,并且利用已经3.1建立的关系数据库,执行查询语句,得出查询结果。

在编制查询语句时,建议首先罗列出关系代数表达式。

也可以利用查询的结果,验证所设计的关系代数表达式的正确性

3.3按照教材第172页习题6.3.1要求,参照习题5.2.1编制的相关查询的关系代数表达式,利用核心数据库查询语言(即核心SQL,不包括GROUPBY、SUM、AVG、MIN、MAX、和COUNT语句)编制查询语句,对在3.1中建立的关系数据库进行查询,并且记录查询结果。

3.4按照教材第178页习题6.4.6要求,利用完全数据库查询语言(完全SQL)编制查询语句,对在3.1中建立的关系数据库进行查询,并且记录查询结果。

3.5选择3.3中最后三个练习题,采用完全SQL编制相关的查询语句,针对在3.1中建立的关系数据库进行查询,记录查询结果和查询的时间。

3.6对比3.3和3.5的查询语句、查询结果和查询花费的时间,比较核心SQL和完全SQL在功能和性能方面的差异。

参考教材

JeffreyD.Ullman,JenniferWidom著,岳丽华,龚育昌等译.数据库系统基础教程(英文版第二版).机械工业出版社,2009.1.

 

实验报告

3.1已录入SQLSever2005的数据库

3.2对于6.2.2中的题目

a)编制的关系表达式为:

select查询语句为:

selectmaker,speed

fromProduct,Laptop

wherehd>30ANDLaptop.model=Product.model

结果截图

b)编制的关系表达式为:

select查询语句为:

selectProduct.model,pricefromProduct,PC

whereProduct.model=PC.modelANDmaker='B'

union

selectProduct.model,pricefromProduct,Laptop

whereProduct.model=Laptop.modelANDmaker='B'

union

selectProduct.model,pricefromProduct,Printer

whereProduct.model=Printer.modelANDmaker='B'

结果截图

c)编制的关系表达式为:

select查询语句为:

(selectdistinctmakerfromProduct,Laptop

whereProduct.model=Laptop.model)

except(selectdistinctmaker

fromProduct,PCwhereProduct.model=PC.model)

结果截图

d)编制的关系表达式为:

select查询语句为:

selectdistinctpc1.hdfromPCpc1,PCpc2

wherepc1.model<>pc2.modelandpc1.hd=pc2.hd

结果截图

e)编制的关系表达式为:

select的查询语句为:

selectpc1.model,pc2.modelfromPCpc1,PCpc2

Wherepc1.ram=pc2.ramandpc1.speed=pc2.speedandpc1.model

结果截图

f)select的查询语句:

selectmakerfromProduct

wheremodelin((selectmodelfrompcwherespeed>=1000)union(selectmodelfromlaptopwherespeed>=1000))

groupbymaker

havingcount(model)>=2

结果截图

3.3对于6.3.1中的题目

a)查询语句为:

selectProduct.maker,PC.speedfromPCjoinProduct

onProduct.model=PC.modelwherePC.speed>1200

结果截图

b)查询语句为:

SELECTmodelFROMProductWHEREmodelin

(SELECTmodelFROMPrinterWHERENOTprice>ANY

(SELECTpricefromPrinter))

结果截图

c)查询语句为:

selectmodelfromLaptopwhereLaptop.speed<

(selecttop1speedfromPCorderbyspeedasc)

结果截图

d)查询语句为:

selectmodel

from((selectmodel,pricefromPC)union(selectmodel,pricefromLaptop)

union(selectmodel,pricefromPrinter))PLPr

whereprice=

(selectPLPr1.price

from((selectmodel,pricefromPC)union(selectmodel,pricefromLaptop)

union(selectmodel,pricefromPrinter))PLPr1,

((selectmodel,pricefromPC)union(selectmodel,pricefromLaptop)

union(selectmodel,pricefromPrinter))PLPr2

wherePLPr1.price<=PLPr2.price)

except

(selectPLPr1.price

from((selectmodel,pricefromPC)union(selectmodel,pricefromLaptop)

union(selectmodel,pricefromPrinter))PLPr1,

((selectmodel,pricefromPC)union(selectmodel,pricefromLaptop)

union(selectmodel,pricefromPrinter))PLPr2

wherePLPr1.price

查询结果为:

e)查询语句为:

selectmaker

fromProduct

wheremodel

in(selectmodelfromPrinterwherecolor='true'andprice<=ALL(selectpricefromPrinter))

查询结果为:

f)查询语句为:

SELECTmakerFROMProductWHEREmodelin

(SELECTmodelFROMPCWHEREspeed>=ALL

(SELECTspeedfromPC)ANDram<=ALL

(SELECTramfrompc))

结果截图

3.4对于6.4.6中的题目

a)查询语句为:

selectavg(cast(speedasreal))fromPC

查询结果为:

b)查询语句为:

selectavg(price)fromLaptopwhereprice>2000

查询结果为:

c)查询语句为:

selectavg(price)fromProduct,PC

whereProduct.model=PC.modelandmaker='A'

查询结果为:

d)查询语句为:

selectavg(price)fromProduct((selectmodel,pricefromPC)UNION(selectmodel,pricefromLaptop))PL

whereProduct.model=PL.modelandProduct.maker='D'

查询结果为:

e)查询语句为:

selectavg(price)fromPC

wherespeedin(selectspeedfromPCgroupbyspeedhavingcount(speed)<2)

查询结果为:

f)查询语句为:

selectmaker,avg(price)fromProduct,Laptop

whereProduct.model=Laptop.modelgroupbymaker

查询结果为:

g)查询语句为:

selectmakerfromProduct

wheretype='PC'groupbymakerhavingcount(model)>=3

查询结果为:

h)查询语句为:

selectmaker,max(price)asMaxPricefromProduct,PC

whereProduct.model=PC.modelgroupbymaker

查询结果为:

i)查询语句为:

selectavg(price)asavgPriceMoreThan800fromPCwherespeed>800

查询结果为:

j)查询语句为:

selectmaker,avg(cast(hdasreal))asavgHdfromProduct,PC

wheremakerin(selectmakerfromProductwheretype

in(selecttypefromProductwhereProduct.type='Printer'))andProduct.model=PC.modelgroupbymaker

查询结果为:

3.5对于6.3.1中的题目

d)查询语句为:

(selectmodelfrompcwhereprice>=all

(selectmax(price)frompc)andprice>=all

(selectmax(price)fromlaptop)andprice>=all

(selectmax(price)fromprinter))

union

(selectmodelfromlaptopwhereprice>=all

(selectmax(price)frompc)andprice>=all

(selectmax(price)fromlaptop)andprice>=all

(selectmax(price)fromprinter))

union

(selectmodelfromprinterwhereprice>=all

(selectmax(price)frompc)andprice>=all

(selectmax(price)fromlaptop)andprice>=all

(selectmax(price)fromprinter))

查询结果为:

e)查询语句为:

selectmakerfromProduct,Printer

whereProduct.model=Printer.modelandcolor='true'andPrinter.price<=all(selectpricefromPrinter)

查询结果为:

f)查询语句为:

selectmakerfrompc,productwherepc.model=product.modelandspeedin(selectmax(speed)frompc)andramin(selectmin(ram)frompc)

 

3.6通过对比3.3和3.5可以得出如下结论:

核心SQL和完全SQL在功能上均可实现相同的功能,但在时间上核心SQL较完全SQL语句耗时,故性能上完全SQL更加优越

实验报告

四、实验小结(包括问题和解决方法、心得体会、意见与建议等)

实验是经过很多次的测试、修改再测试、再修改才完成的。

也就是在多次的测试修改的过程中使我学发现了很多平时上课发现不了的问题,也发现了自己学习这门课程的薄弱的地方和学的不足的地方。

通过实验期间的发现问题、分析问题、查找问题原因、解决问题及进一步完善考务管理系统的过程,我的能力和水平有一定程度的提高。

经过一次独立完成系统给我以后编程打下了基础,让我面对的不再是茫然和无措,而是有条不紊的思绪和完成的信心。

所以这次实验对我来说是一笔极大的财富。

  当然,在实验中我也有很多不足的地方,系统也有需要进一步完善的地方,这主要是我对asp与sqlserver数据库的连接和应用不熟悉和经验不足的原因造成的。

所以我还要在以后继续学习,以求做的更好。

五、指导教师评语

成绩

批阅人

日期

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 物理

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

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