数据结库原理实验报告Word文件下载.docx

上传人:b****5 文档编号:16428521 上传时间:2022-11-23 格式:DOCX 页数:28 大小:1.14MB
下载 相关 举报
数据结库原理实验报告Word文件下载.docx_第1页
第1页 / 共28页
数据结库原理实验报告Word文件下载.docx_第2页
第2页 / 共28页
数据结库原理实验报告Word文件下载.docx_第3页
第3页 / 共28页
数据结库原理实验报告Word文件下载.docx_第4页
第4页 / 共28页
数据结库原理实验报告Word文件下载.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

数据结库原理实验报告Word文件下载.docx

《数据结库原理实验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《数据结库原理实验报告Word文件下载.docx(28页珍藏版)》请在冰豆网上搜索。

数据结库原理实验报告Word文件下载.docx

createindexxsnoonagents(aid)

createindexxsnoonproducts(pid)

createindexxsnoonorders(ordan)

(5)

dropindexcustomer.xsno

dropindexagents.xsno

dropindexproducts.xsno

dropindexorders.xsno

 

1.2

(1)select*fromcourses

(2)selectsidfromchoices

(3)selectcidfromcourseswherehour<

88

(4)selectsidfromchoicesgroupbysidhavingsum(score)>

400

(5)selectcount(cid)fromcourses

(6)selectcid,count(sid)fromchoicesgroupbycid

(7)selectsidfromchoiceswherescore>

60groupbysidhavingcount(cid)>

2

(8)

selectsid,count(cid),avg(score)fromchoicesgroupbysid

(9)

selectstudents.sid,snamefromstudents,choices,courses

wherestudents.sid=choices.sidandchoices.cid=courses.cidandame='

java'

(10)

selectchoices.cid,choices.scorefromchoices,studentswheresname='

sssht'

andchoices.sid=students.sid

selectcid,scorefromchoiceswheresidin(selectstudents.sidfromstudentswheresname='

(11)

selectamefromcoursesasc1,coursesasc2wherec1.hour>

c2.hourandame='

c++'

(12)selectsid,snamefromstudentswheresidin(

selectc1.sidfromchoicesasc1,choicesasc2wherec1.score>

c2.scoreandc1.cid=c2.cid

andc2.sid=(selectsidfromstudentswheresname='

znkoo'

andc1.cid=(selectcidfromcourseswherecname='

))

(13)selectsnamefromstudentswheregradein(selectgradefromstudentswheresidin('

883794999'

'

850955252'

(14)

selectsnamefromstudentswheresidnotin(selectsidfromchoiceswherecid=(selectcidfromcourseswherecname='

(15)

select*fromcourseswherehour<

=all(selecthourfromcourses)

(16)

selectchoices.tid,cidfromchoiceswherenotexists(select*fromteacherswhereteachers.salary>

=(

selectsalaryfromteacherswhereteachers.tid=choices.tid))

(17)

selectsidfromchoiceswherescore=(selectmax(score)fromchoiceswherecid=(selectcidfromcourseswherecname='

erp'

(18)

selectcnamefromcourseswherecidnotin(selectcidfromchoices)

(19)

selectcnamefromcourseswherecid=some(selectcidfromchoiceswheretid=some(selecttidfromcourses,choiceswherecname='

uml'

andcourses.cid=choices.cid))

(20)

selectsnamefromstudentswherenotexists(select*fromchoicesasc1wherenotexists(select*fromchoicesasc2wherec2.sid=students.sidandc2.cid=c1.cidandc2.tid='

200102901'

(21)

selectsidfromchoices,courseswherecourses.cid=choices.cidandame='

database'

unionselectsidfromchoices,courseswherecourses.cid=choices.cidandame='

(22)

selectx.sidfromchoicesasx,choicesasywhere(x.cid=(selectcidfromcourseswherecname='

andy.cid=(selectcidfromcourseswherecname='

))andx.sid=y.sid

(23)

))andx.sid=y.sidandnot(y.cid=(selectcidfromcourseswherecname='

1.3

(1)insertintostudents(sid,sname)values('

800022222'

WangLan'

insertintoteachersvalues('

200001000'

LXL'

s4zrck@'

3024'

updateteacherssetsalary=4000wheretid='

200010493'

updateteacherssetsalary=2500wheresalary<

2500

updatechoicessettid=(selecttidfromteacherswheretname='

rnupx'

)wheretid='

200016731'

(6)

updatestudentssetgrade=2001wheresid='

800071780'

(7)

deletefromcourseswherecidnotin(selectcidfromchoicesgroupbycid)

deletefromstudentswheregrade<

1998

deletefromstudentswheresidnotin(selectsidfromchoicesgroupbysid)

deletefromchoiceswherescore<

60

1.4

createviewviewcasselectchoices.no,choices.sid,choices.tid,ame,choices.scorefromchoices,courseswherechoices.cid=courses.cid

createviewviewsasselectchoices.no,students.sname,choices.tid,choices.cid,choices.scorefromchoices,studentswherechoices.sid=students.sid

createviews1(sid,aname,grade)as

selectstudents.sid,students.sname,students.gradefromstudentswheregrade>

select*fromviewswheresname='

uxjof'

selectsid,scorefromviewcwherecname='

insertintos1values('

60000001'

Lily'

2001)

createviews2(sid,sname,grade)as

selectsid,sname,gradefromstudentswheregrade>

1998withcheckoption

插入元组:

insertintos2values('

1997)

结果讨论:

加入了WITHCHECKOPTION子句后,使得所有的对视图的插入或更新操作都必须满足定义视图时所指明的条件,在本题就是GRADE>

1998,题目中要插入的元组并不满足这个条件,GRADE=1997<

1998。

所以本题中插入这个元组是不成功的。

删除元组:

deletefroms2wheregrade=1999

虽然要删除的元组并没有违反视图定义的约束(GRADE=1999>

1998),但是,由于基本表STUDENTS和表CHOICES之间存在引用完整性约束,而将GRADE=1999的元组删除将违反了它们之间的引用完整性约束,所以出现了上面的错误。

updateviewssetscore=score+5wheresname='

dropviewviewcdropviewviewsdropviews1dropviews2

1.5

grantselectonstudentstopublic

(2)

grantselect,updateoncoursestopublic

grantselect,update(salary)onteacherstouser1withgrantoption

grantselect,update(score)onchoicestouser2

createviewTVasselecttid,tname,email,salaryfromteachers

grantselectonTVtouser2

(6)以用户USER1身份登录数据库后,执行,

grantselectonteacherstouser2withnooption

(7)以用户USER2身份登录数据库后,执行,

grantselectonteacherstouser3withnooption

以用户USER3身份登录数据库后,执行,

revokeselectonteachersfromuser1cascade

操作不成功,取消授权操作存在级联效应。

revokeselect,updateoncoursesfromuser1,user2

1.6

(1)selectcid,hour*18fromcourses

selectcount(*)

fromchoiceswherecid=(selectcidfromcourseswherecname='

selectcount(*)fromchoiceswherescore>

=60andcid=(selectcidfromcourseswherecname='

selectcount(*)fromchoiceswherescore<

60andcid=(selectcidfromcourseswherecname='

selectcount(*)fromchoiceswherescoreisnotnullandcid=(selectcidfromcourseswherecname='

分析:

在数据库中存在490个SCORE的值为NULL的元组。

(3)NULL的项出现在结果中,被当做最小值看待。

selectdistinctscorefromchoiceswherecid=(selectcidfromcourseswherecname='

)orderbyscore

selectdistinctgradefromstudentsgroupbygrade

得到15个组,现实中有14个年级。

selectavg(score),count(*),max(score),min(score)fromchoicesgroupbycid

selectgradefromstudentswheregrade>

=all(selectgradefromstudents)

selectcount(*)fromstudents,teacherswhereteachers.tid=students.sid

实验2

2.1

createtableClass(Class_idvarchar(4),namevarchar(10),Deparmentvarchar(20)constraintPK_ClassPrimarykey(Class_id))

begintransactionT3insertintoclassvalues('

00001'

01CSC'

CS'

begintransactionT4insertintoclassvalues('

committransactionT4committransactionT3

由于T4中插入违法,T4失败,而且整个T3事物回滚,T3中的插入也不成功。

2.2

相应结果:

数据库不允许删除students表以及course表中对应的元组。

由于ondeleterestrict的约束,数据库不允许任何引用关系存在对应元组时进行删除操作。

约束ondeletesetNULL是将要删除的对应元组的外键置空值,如果cno以及sno不是SC表的主键,删除操作是可以完成的,但是由于主键不可以取空值,所以删除操作不可以进行。

createtablehelp(sidchar(8),snamevarchar(20),help_idchar(8)notnull

constraintPK_helpprimarykey(sid))

altertablehelp

addconstraintFK_helpforeignkey(help_id)referenceshelp(help_id)

createtableleader(sidchar(9),snamevarchar(20),myleaderchar(9)

constraintPK_leaderprimarykey(sid))

createtablemonitor(sidchar(9),snamevarchar(20),mymonitorchar(9)

constraintPK_monitorprimarykey(sid)constraintFK_monitorforeignkey(mymonitor)referencesleader(sid))

altertableleader

addconstraintFK_leaderforeignkey(myleader)referencesmonitor(sid)

2.3

createtableworker(Numberchar(5),Namechar(8)constraintU1unique,Sexchar

(1),SageintconstraintU2check(Sage<

=28),Departmentchar(20),constraintPK_WorkerPrimaryKey(Number))

altertableworkeraddconstraintU3check(sage>

=0);

GOcreaterulerule_sageas@valuebetween1and100

goexecsp_bindrulerule_sage,'

worker.[sage]'

;

2.4

GOcreatetriggerT4onworker

forinsertas

if(selectsagefrominserted)<

=(selectmax(sage)fromworker)

beginprint'

thesageofcouplemustbemorethantheexistedcouplesage!

'

rollbacktransactionend

USESchool

GOcreatetriggerT5onworker

forupdateasif(selectsagefrominserted)<

=(selectsagefromdeleted)

thesageofnewcouplemustbemorethanthesageofoldcouple!

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

当前位置:首页 > 初中教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1