数据库题库答案.docx

上传人:夺命阿水 文档编号:909895 上传时间:2024-01-12 格式:DOCX 页数:65 大小:50.23KB
返回 下载 相关 举报
数据库题库答案.docx_第1页
第1页 / 共65页
数据库题库答案.docx_第2页
第2页 / 共65页
数据库题库答案.docx_第3页
第3页 / 共65页
数据库题库答案.docx_第4页
第4页 / 共65页
数据库题库答案.docx_第5页
第5页 / 共65页
点击查看更多>>
资源描述

《数据库题库答案.docx》由会员分享,可在线阅读,更多相关《数据库题库答案.docx(65页珍藏版)》请在课桌文档上搜索。

1、第二套试卷1 .Listfoursignificantdifferencesbetweenafile-processingsystemandaDBMS.Answer:1)两种系统都包含数据收集和一套存取那些数据的程序,DBMS允许物理上的和逻辑上的数据存取,而文件处理系统只能进行物理上的存取。2 .DBMS能够通过授权所有程序访问一个物理数据块,来减少数据的冗余,而在文件处理系统中,一个程序所写的数据不能被另一个程序读取。3 )DBMS允许灵活的对数据进行访问,而文件处理系统则只允许预定的数据访问。4 )DBMS允许多个用户同时访问同一数据,而文件处理系统则只允许一个或多个程序同时访问不同的数

2、据,只有当两个程序对文件进行只读操作时,才允许并发地访问该文件。2. Whywouldyouchooseadatabasesysteminsteadofsimplystoringdatainoperatingsystemfiles?Whenwoulditmakesensenottouseadatabasesystem?l使用DBMS存储数据并通过WEB浏览器浏览数据。通过WEB可存取的表单界面来产生查询请示,并使用诸如HTML的标记语言将查询结果格式化,从而便于在浏览器中显示!20一个原因为DBMS是一个复杂的软件,并为如处理多个并发请求之类的工作载荷进行了优化,因此,它的性能可能对一些如具有

3、严格实时约束的应用程序或带有一些定义明确的关键操作并且为这些操作必须编写有效的客户代码的应用程序之类的不是很适合。另一个原因是某些应用程序可能需要以查询语言不能支持的开工来操纵数据。3. Whatislogicaldataindependenceandwhyisitimportant?逻辑数据独立性是指用户的应用程序与数据库的逻辑结构是相互独立的,即,当数据的逻辑结构改变时,用户程序也可以不变。数据逻辑结构改变时,不一定要求修改程序,程序对数据使用的改变也不一定要求修改全局数据结构,使进一步实现深层次数据共享成为可能。4. Whichofthefollowingplaysanimportant

4、roleinrepresentinginformationabouttherealworldinadatabase?Explainbriefly.1) .Thedatadefinitionlanguage.2) .Thedatamanipulationlanguage.3) .Thebuffermanager.4) .Thedatamodel.Answer:1) .Thedatadefinitionlanguage.数据定义语言(DataDefinitionLanguage,DDL)是SQL语言集中负责数据结构定义与数据库对象定义的语言,由CREATE、ALTER与DRoP三个语法所组成最早是

5、由Codasyl(ConferenceonDataSystemsLanguages)数据模型开始,现在被纳入SQL指令中作为其中一个子集。目前大多数的DBMS都支持对数据库对象的DDL操作,部份数据库(如PostgreSQL)可把DDL放在交易指令中,也就是它可以被撤回(RoIIback)o较新版本的DBMS会参加DDL专用的触发程序,让数据库管理员可以追踪来自DDL的修改。2) .Thedatamanipulationlanguage.数据操纵语言DMLDataManipulationLanguage,用户通过它可以实现对数据库的根本操作。例如,对表中数据的插入、删除和修改。3) .Theb

6、uffermanager.4) .Thedatamodel.数据模型数据(data是描述事物的符号记录。模型Model)是现实世界的抽象。数据模型DataModel是数据特征的抽象,是数据库管理的教学形式框架。数据库系统中用以提供信息表示和操作手段的形式构架。数据模型包括数据库数据的结构局部、数据库数据的操作局部和数据库数据的约束条件。5) WhataretheresponsibilitiesofaDBA?1文件管理互动2完整性约束3平安性约束4备份和恢复5并发控制6) Acompanydatabaseneedstostoreinformationaboutemployees(identifi

7、edbyssn,withsalaryandphoneasattributes),departments(identifiedbydno,withdnameandbudgetasattributes),andchildrenofemployees(withnameandageasattributes).Employeesworkindepartments;eachdepartmentismanagedbyanemployee;achildmustbeidentifieduniquelybynamewhentheparent(whoisanemployee;assumethatonlyonepar

8、entworksforthecompany)isknown.Wearenotinterestedininformationaboutachildoncetheparentleavesthecompany.DrawanERdiagramthatcapturesthisinformation.7) ConsiderthescenariofromExercise6,whereyoudesignedanERdiagramforacompanydatabase.WriteSQLstatementstocreatethecorrespondingrelationsandcaptureasmanyofthe

9、constraintsaspossible.Ifyoucannotcapturesomeconstraints,explainwhy.AnswerThefollowingSQLstatementscreatethecorrespondingrelations.CREATETABLEEmployees(ssnCHAR(IO),salINTEGER,phoneCHAR(13),PRIMARYKEY(ssn)CREATETABLEDepartments(dnoINTEGER,budgetINTEGER,dnameCHAR(20),PRIMARYKEY(dno)CREATETABLEWorksin(s

10、snCHAR(IO),dnoINTEGER,PRIMARYKEY(ssn,dno),FOREIGNKEY(ssn)REFERENCESEmployees,FOREIGNKEY(dno)REFERENCESDepartments)CREATETABLEManages(ssnCHAR(IO)1dnoINTEGER,PRIMARYKEY(dno),FOREIGNKEY(ssn)REFERENCESEmployees,FOREIGNKEY(dno)REFERENCESDepartments)CREATETABLEDependents(ssnCHAR(IO)znameCHAR(IO),ageINTEGE

11、R,PRIMARYKEY(ssn,name),FOREIGNKEY(ssn)REFERENCESEmployees,ONDELETECASCADE)8) Considerthefollowingrelations:Student(snum:integer;sname:string,major:string,level:string,age:integer)Class(name:string,meetsat:string,room:string,1id:integer)Enrolled(snum:integer;cname:string)Faculty(fid:integer;fname:str

12、ing,deptid:integer)Themeaningoftheserelationsisstraightforward;forexample,Enrolledhasonerecordperstudent-classpairsuchthatthestudentisenrolledintheclass.WritethefollowingqueriesinSQLNoduplicatesshouldbeprintedinanyoftheanswers.1) .Findthenamesoffacultymembersforwhomthecombinedenrollmentofthecoursest

13、hattheyteachislessthanfive2) .Foreachlevel,printthelevelandtheaverageageofstudentsforthatlevel.3) .ForalllevelsexceptJR,printthelevelandtheaverageageofstudentsforthatlevel.4) .ForeachfacultymemberthathastaughtclassesonlyinroomR128,printthefacultymember*snameandthetotalnumberofclassessheorhehastaught

14、5) .Findthenamesofstudentsenrolledinthemaximumnumberofclasses6) .Findthenamesofstudentsnotenrolledinanyclass.Anwser:1. SELECTDISTINCTEfnameFROMFacultyFWHERE5(SELECTCOUNT(E.snum)FROMClassC,EnrolledEWHEREC.name=EameANDCfid=Efid)2. SELECTS.level,AVG(S.age)FROMStudentSGROUPBYSJeveI3. SELECTSJeveIzAVG(S.

15、age)FROMStudentSWHERES.level,JR,GROUPBYS.level4. SELECTEfname,COUNT(*)ASCourseCountFROMFacultyF,ClassCWHERERfid=CfidGROUPBYFzfid,EfnameHAVINGEVERY(C.room=R128)5. SELECTDISTINCTS.snameFROMStudentSWHERES.snumIN(SELECTE.snumGROUPBYE.snumHAVINGCOUNT(*)=ALL(SELECTCOUNT(*)FROMEnrolledE2GROUPBYE2.snum)6. S

16、ELECTDISTINCTS.snameFROMStudentSWHERES.snumNOTIN(SELECTE.snumFROMEnrolledE)第三套试卷1 .Explainthefollowingtermsbriefly:attribute,domain,entity,relationship,one-to-manyrelationship,many-to-manyrelationship.2 .属性是实体集中每个成员具有的描述性性质;3 .域在文件系统中,有时也称做字段,是指数据中不可再分的根本单元。一个域包含一个值。4 .实体是现实世界中可区别于其他对象的“事件或“物体。每个实体都

17、有一组属性,其中一局部属性的取值可以唯一标识一个实体;5 .联系是多个实体间的相互关联。6 .一对多来关系,A中的一个实体可以和B中的任意数目实体相联系,而B中的一个实体至多同A中的一个实体相联系。7 .多对多关系,A中的一个实体可以和B中的任意数目实体相联系,而B中的一个实体也可以同A中的任意数目实体相联系。2. GiventworelationsRlandR2,whereRlcontainsNltuples,R2containsN2tuples,andN2Nl0,givetheminimumandmaximumpossiblesizes(intuples)fortheresultingre

18、lationproducedbyeachofthefollowingrelationalalgebraexpressions.Ineachcase,stateanyassumptionsabouttheschemasforRlandR2neededtomaketheexpressionmeaningful:(1) RlUR2,RlnR2,Rl-R2,R1R2,(5)a=s(Rl),(6)a(Rl),3. NotownRecordshasdecidedtostoreinformationaboutmusicianswho资料4. ConsidertheNotowndatabasefromExer

19、cise3.YouhavedecidedtorecommendthatNotownusearelationaldatabasesystemtostorecompanydata.ShowtheSQLstatementsforcreatingrelationscorrespondingtotheentitysetsandrelationshipsetsinyourdesign.IdentifyanyconstraintsintheERdiagramthatyouareunabletocaptureintheSQLstatementsandbrieflyexplainwhyyoucouldnotex

20、pressthem.AnswerThefollowingSQLstatementscreatethecorrespondingrelations.1. CREATETABLEMusicians(ssnCHAR(IO),nameCHAR(30),PRIMARYKEY(ssn)2. CREATETABLEInstruments(instrldCHAR(IO)zdnameCHAR(30),keyCHAR(5),PRIMARYKEY(instrld)3. CREATETABLEPlays(ssnCHAR(IO),instrldINTEGER,PRIMARYKEY(ssn,instrld),FOREIG

21、NKEY(ssn)REFERENCESMusicians,FOREIGNKEY(instrld)REFERENCESInstruments)4. CREATETABLESongsAppears(songldINTEGER,authorCHAR(30),titleCHAR(30),albumldentilierINTEGERNOTNULL,PRIMARYKEY(songld)zFOREIGNKEY(albumldentilier)ReferencesAlbumProducer)5. CREATETABLETelephoneHome(phoneCHAR(Il)zaddressCHAR(30),PR

22、IMARYKEY(phone),FOREIGNKEY(address)REFERENCESPlace,6. CREATETABLELives(ssnCHAR(IO),phoneCHAR(Il)zaddressCHAR(30),PRIMARYKEY(ssn,address)fFOREIGNKEY(phone,address)ReferencesTelephoneHome,FOREIGNKEY(ssn)REFERENCESMusicians)7. CREATETABLEPlace(addressCHAR(30)8. CREATETABLEPerform(songldINTEGER,ssnCHAR(

23、IO),PRIMARYKEY(ssn,songld),FOREIGNKEY(songld)REFERENCESSongs,FoR日GNKEY(ssn)REFERENCESMusicians)9. CREATETABLEAlbumProducer(albumldentifierINTEGER,ssnCHAR(IO),CopyrightDateDATE,speedINTEGER,titleCHAR(30),PRIMARYKEY(albumldentiiier),FOREIGNKEY(ssn)REFERENCESMusicians)5.Considerthefollowingschema:Suppl

24、iers(sid:integer;sname:string,address:string)Parts(pid:integer;pname:string,COlo匚string)Catalog(sid:integer,pid:integer;cost:real)TheCatalogrelationliststhepriceschargedforpartsbySuppliers.WritethefollowingqueriesinSQL:1. Findthepnamesofpartsforwhichthereissomesupplier.2. Findthesnamesofsupplierswho

25、supplyeverypart.3. Findthesnamesofsupplierswhosupplyeveryredpart.4. FindthepnamesofpartssuppliedbyAcmeWidgetSuppliersandnooneelse.5. Findthesidsofsupplierswhochargemoreforsomepartthantheaveragecostofthatpart(averagedoverallthesupplierswhosupplythatpart).6. Foreachpart,Iindthesnameofthesupplierwhocha

26、rgesthemostforthatpart.Answer:1. SELECTDISTINCTRpnameFROMPartsP,CatalogCWHERERpid=C.pid2. SELECTS.snameFROMSuppliersSWHERENOTEXISTS(SELECTRpidFROMPartsP)EXCEPT(SELECTGpidFROMCatalogCWHERECsid=S.sid)3. SELECTS.snameFROMSuppliersSWHERENOTEXISTS(SELECTRpidFROMPartsPWHERERcolor=,Red,)EXCEPT(SELECTCpidFR

27、OMCatalogC,PartsPWHERECsid=S.sidANDC.pid=RpidANDRcolor=Red)4. SELECTRpnameFROMPartsRCatalogC,SuppliersSWHERERpid=C.pidANDC.sid=S.sidANDS.sname=,AcmeWidgetSuppliers,ANDNOTEXISTS(SELECT*FROMCatalogCl,SuppliersSlWHERERpid=Cl.pidANDCl.sid=Sl.sidANDSl.snameAcmeWidgetSuppliers1)5. SELECTDISTINCTC.sidFROMC

28、atalogCWHEREC.cost(SELECTAVG(Clxost)FROMCatalogClWHERECl.pid=C.pid)6. SELECTRpid,S.snameFROMPartsRSuppliersS,CatalogCWHEREC.pid=RpidANDC.sid=S.sidANDC.cost=(SELECTMAX(Clxost)FROMCatalogClWHERECl.pid=Rpid)6. Foreachpart,Iindthesnameofthesupplierwhochargesthemostforthatpart.1 Listsixmajorstepsthatyouw

29、ouldtakeinsettingupadatabaseforaparticularenterprise.1 .定义企业的高标准要求这一步生成一个系统要求标准文件2 .定义一个包含所有适宜数据类型及数据关系的模型3 .定义在数据上的完整性约束4 .定义物理层5 .对每一个定期根底上问题的解决如被员工执行的任务,定义一个用户接口来执行任务,并且写出实现用户接口必要的应用程序。6 .创立或初始化数据库。2Listtworeasonswhywemaychoosetodefineaview.简单性。看到的就是需要的。视图不仅可以简化用户对数据的理解,也可以简化他们的操作。那些被经常使用的查询可以被定义

30、为视图,从而使得用户不必为以后的操作每次指定全部的条件。*平安性。通过视图用户只能查询和修改他们所能见到的数据。数据库中的其它数据则既看不见也取不到。数据库授权命令可以使每个用户对数据库的检索限制到特定的数据库对象上,但不能授权到数据库特定行和特定的列上。通过视图,用户可以被限制在数据的不同子集上:使用权限可被限制在另一视图的一个子集上,或是一些视图和基表合并后的子集上。*逻辑数据独立性。视图可帮助用户屏蔽真实表结构变化带来的影响。3Letthefollowingrelationschemasbegiven:R=(A,B,C)S=(D,E,F)Letrelationsr(R)ands(三)be

31、given.Givethemeaningofeachoneexpressiona. 11A(r)b. =i7(r)c. rsd. 11a,f(c=D(rXs)第四套试卷4. ComputerSciencesDepartmentfrequentfliershavebeencomplainingtoDane资料anser:l.Sinceallairlineemployeesbelongtoaunion,thereisacoveringconstraintontheEmployeesISAhierarchy.2. Youcannotnotetheexperttechnicianconstraintt

32、heFAArequiresinanERdiagram.ThereisnonotationforequivalenceinanERdiagramandthisiswhatisneeded:theExpertrelationmustbeequivalenttotheTyperelation.5. TranslateyourERdiagramfromExercise4intoarelationalschema,andshowtheSQLstatementsneededtocreatetherelations,usingonlykeyandnullconstraints.Ifyourtranslati

33、oncannotcaptureanyconstraintsintheERdiagram,explainwhy.InExercise4,youalsomodifiedtheERdiagramtoincludetheconstraintthattestsonaplanemustbeconductedbyatechnicianwhoisanexpertonthatmodel.CanyoumodifytheSQLstatementsdefiningtherelationsobtainedbymappingtheERdiagramtocheckthisconstraint?AnswerThefollow

34、ingSQLstatementscreatethecorrespondingrelations.1. CREATETABLEExpert(ssnCHAR(Il),modelnoINTEGER,PRIMARYKEY(ssn,modelno),FOREIGNKEY(ssn)REFERENCESTechnician,FOREIGNKEY(modelno)REFERENCESModels)Theparticipationconstraintcannotbecapturedinthetable.2. CREATETABLEModels(modelnoINTEGER,capacityINTEGER,wei

35、ghtINTEGER,PRIMARYKEY(modelno)3. CREATETABLEEmployees(ssnCHAR(Il),unionmemnoINTEGER,PRIMARYKEY(ssn)4. CREATETABLETechnicianemp(ssnCHAR(Il),nameCHAR(20),addressCHAR(20),phonenoCHAR(14)zPRIMARYKEY(ssn),FOREIGNKEY(ssn)REFERENCESEmployeesONDELETECASCADE)5. CREATETABLETrafficcontrolemp(ssnCHAR(Il)zexamda

36、teDATE,PRIMARYKEY(ssn)lFOREIGNKEY(ssn)REFERENCESEmployeesONDELETECASCADE)6. CREATETABLEPlaneType(regnoINTEGER,modelnoINTEGER,PRIMARYKEY(regno)zFOREIGNKEY(modelno)REFERENCESModels)7. CREATETABLETestinfo(FFAnoINTEGER,ssnCHAR(Il)zregnoINTEGER,hoursINTEGER,dateDATE,scoreINTEGER,PRIMARYKEY(ssn,regno,FFAn

37、o),FOREIGNKEY(regno)REFERENCESPlaneType,FOREIGNKEY(FAAno)REFERENCESTestzFOREIGNKEY(ssn)R讦ERENCESEmployees)8. TheconstraintthattestsonaplanemustbeconductedbyatechnicianwhoisanexpertonthatmodelcanbeexpressedinSQLasfollows.CREATETABLETestinfo(FFAnoINTEGER,ssnCHAR(Il),regnoINTEGER,hoursINTEGER,dateDATE,

38、scoreINTEGER,PRIMARYKEY(ssn,regno,FFAno),FOREIGNKEY(regno)REFERENCESPlaneType,FoR日GNKEY(FAAno)REFERENCESTest,FOREIGNKEY(ssn)REFERENCESTechnicianemp)CONSTRAINTMODELCHECK(SELECT*FROMExpert,TypeWHEREEpert.ssn=ssnANDExpertmodelno=Type.modelnoANDType.regno=regno)6Considerthefollowingschema:Suppliers(sid:

39、integer;sname:string,address:string)Parts(pid:integer;pname:string,color:string)Catalog(sid:integer,pid:integer;cost:real)TheCatalogrelationliststhepriceschargedforpartsbySuppliers.WritethefollowingqueriesinSQL:11.Foreachpart,findthesnameofthesupplierwhochargesthemostforthatpart.2 .Findthesidsofsupp

40、lierswhosupplyonlyredparts.3 .Findthesidsofsupplierswhosupplyaredpartandagreenpart.4 .Findthesidsofsupplierswhosupplyaredpartoragreenpart.51 .Foreverysupplierthatonlysuppliesgreenparts,printthenameofthesupplierandthetotalnumberofpartsthatshesupplies.52 .Foreverysupplierthatsuppliesagreenpartandaredp

41、art,printthenameandpriceofthemostexpensivepartthatshesupplies.Answer:1. SELECTRpid,S.snameFROMPartsP1SuppliersS,CatalogCWHERECpid=RpidANDCsid=S.sidANDC.cost=(SELECTMAX(Cl.cost)FROMCatalogClWHERECl.pid=Rpid)2. SELECTDISTINCTCsidFROMCatalogCWHERENOTEXISTS(SELECT*FROMPartsPWHERERpid=CpidANDRcolor,Red,)

42、3. SELECTDISTINCTGsidFROMCatalogC1PartsPWHERECpid=RpidANDRcolor=,Red,INTERSECTSELECTDISTINCTCLsidFROMCatalogCLPartsPlWHERECl.pid=Pl.pidANDPl.color=lGreen,4. SELECTDISTINCTC.sidFROMCatalogC,PartsPWHERECpid=P.pidANDRcolor=RedUNIONSELECTDISTINCTCLsidFROMCatalogCl,PartsPlWHERECl.pid=Pl.pidANDPl.color=Gr

43、een5. SELECTS.sname,CONT(*)asPartCountFROMSuppliersS,PartsP,CatalogCWHERERpid=CpidANDCsid=S.sidGROUPBYS.sname,S.sidHAVINGEVERY(Rcolor=rGreen,)6. SELECTS.sname,MAX(Cxost)asMaxCostFROMSuppliersS,PartsP,CatalogCWHERERpid=C.pidANDCsid=S.sidGROUPBYS.sname,S.sidHAVINGANY(Rcolor=green,)ANDANY(Rcolor=,red第五

44、套试卷1. LetthefollowingrelationschemasbegivenR=(A,B,C)S=(D,E,F)Letrelationsr(R)ands(三)begiven.GiveanexpressioninSQLthatisequivalenttoeachofthefollowingqueries.a. 11a()b. ob=17(r)c. rsd. 11a,f(c=D(rs)2.Makealistofsecurityconcernsforabank.Foreachitemonyourlist,statewhetherthisconcernrelatestophysicalsec

45、urity,humansecurity,operatingsystemsecurity,ordatabasesecurity.Answer:Letusconsidertheproblemofprotectingoursamplebankdatabase.Somesecuritymeasuresateachofthefourlevelsarementionedbelow-a. Physicallevel-Thesystemfromwhichtherelationscanbeaccessedandmodifiedshouldbeplacedinalocked,well-guarded,andimp

46、regnableroom.b. Humanlevel-Aproperkeytransferpolicyshouldbeenforcedforrestrictingaccesstothewsystemroommentionedabove.Passwordsforgainingaccesstothedatabaseshouldbeknownonlytotrustedusers.c. OperatingSystemlevel-Loginpasswordsshouldbedifficulttoguessandtheyshouldbechangedregularly.Nousershouldbeable

47、togainunauthorizedaccesstothesystemduetoasoftwarebugintheoperatingsystem.d. DatabaseSystemlevel-Theusersshouldbeauthorizedaccessonlytorelevantpartsofthedatabase.Forexample,abanktellershouldbeallowedtomodifyvaluesforthecustomer*sbalance,butnotforherownsalary.3. ThePrescriptions-R-Xchainofpharmacieshasofferedtogiveyoua资料Answer1.TheERdiagramisshowninFigure2.11.4. Ifthedrugistobe

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

当前位置:首页 > 在线阅读 > 生活休闲


备案号:宁ICP备20000045号-1

经营许可证:宁B2-20210002

宁公网安备 64010402000986号