数据库题库答案.docx
- 文档编号:24893205
- 上传时间:2023-06-02
- 格式:DOCX
- 页数:39
- 大小:180.82KB
数据库题库答案.docx
《数据库题库答案.docx》由会员分享,可在线阅读,更多相关《数据库题库答案.docx(39页珍藏版)》请在冰豆网上搜索。
数据库题库答案
第二套试卷
1.Listfoursignificantdifferencesbetweenafile-processingsystemandaDBMS.
Answer:
1)两种系统都包含数据收集和一套存取那些数据的程序,DBMS允许物理上的和逻辑上的数据存取,而文件处理系统只能进行物理上的存取。
2_DBMS能够通过授权所有程序访问一个物理数据块,来减少数据的冗余,而在文件处理系统中,一个程序所写的数据不能被另一个程序读取。
3)DBMS允许灵活的对数据进行访问,而文件处理系统则只允许预定的数据访问。
4)DBMS允许多个用户同时访问同一数据,而文件处理系统则只允许一个或多个程序同时访问不同的数据,只有当两个程序对文件进行只读操作时,才允许并发地访问该文件。
2.Whywouldyouchooseadatabasesysteminsteadofsimplystoringdatainoperatingsystemfiles?
Whenwoulditmakesensenottouseadatabasesystem?
1。
使用DBMS存储数据并通过WEB浏览器浏览数据。
通过WEB可存取的表单界面来产生查询请示,并使用诸如HTML的标记语言将查询结果格式化,从而便于在浏览器中显示!
2。
一个原因为DBMS是一个复杂的软件,并为如处理多个并发请求之类的工作载荷进行了优化,因此,它的性能可能对一些如具有严格实时约束的应用程序或带有一些定义明确的关键操作并且为这些操作必须编写有效的客户代码的应用程序之类的不是很适合。
另一个原因是某些应用程序可能需要以查询语言不能支持的开工来操纵数据。
3.Whatislogicaldataindependenceandwhyisitimportant?
逻辑数据独立性是指用户的应用程序与数据库的逻辑结构是相互独立的,即,当数据的逻辑结构改变时,用户程序也可以不变。
数据逻辑结构改变时,不一定要求修改程序,程序对数据使用的改变也不一定要求修改全局数据结构,使进一步实现深层次数据共享成为可能。
4.Whichofthefollowingplaysanimportantroleinrepresentinginformationabouttherealworldinadatabase?
Explainbriefly.
1).Thedatadefinitionlanguage.
2).Thedatamanipulationlanguage.
3).Thebuffermanager.
4).Thedatamodel.
Answer:
1).Thedatadefinitionlanguage.
数据定义语言(DataDefinitionLanguage,DDL)是SQL语言集中负责数据结构定义与数据库对象定义的语言,由CREATE、ALTER与DROP三个语法所组成,最早是由Codasyl(ConferenceonDataSystemsLanguages)数据模型开始,现在被纳入SQL指令中作为其中一个子集。
目前大多数的DBMS都支持对数据库对象的DDL操作,部份数据库(如PostgreSQL)可把DDL放在交易指令中,也就是它可以被撤回(Rollback)。
较新版本的DBMS会加入DDL专用的触发程序,让数据库管理员可以追踪来自DDL的修改。
2).Thedatamanipulationlanguage.
数据操纵语言DML(DataManipulationLanguage),用户通过它可以实现对数据库的基本操作。
例如,对表中数据的插入、删除和修改。
3).Thebuffermanager.
4).Thedatamodel.
数据模型
数据(data)是描述事物的符号记录。
模型(Model)是现实世界的抽象。
数据模型(DataModel)是数据特征的抽象,是数据库管理的教学形式框架。
数据库系统中用以提供信息表示和操作手段的形式构架。
数据模型包括数据库数据的结构部分、数据库数据的操作部分和数据库数据的约束条件。
5.WhataretheresponsibilitiesofaDBA?
1文件管理互动2完整性约束3安全性约束4备份和恢复5并发控制
6Acompanydatabaseneedstostoreinformationaboutemployees(identifiedbyssn,withsalaryandphoneasattributes),departments(identifiedbydno,withdnameandbudgetasattributes),andchildrenofemployees(withnameandageasattributes).Employeesworkindepartments;eachdepartmentismanagedbyanemployee;achildmustbeidentifieduniquelybynamewhentheparent(whoisanemployee;assumethatonlyoneparentworksforthecompany)isknown.Wearenotinterestedininformationaboutachildoncetheparentleavesthecompany.
DrawanERdiagramthatcapturesthisinformation.
7ConsiderthescenariofromExercise6,whereyoudesignedanERdiagramforacompanydatabase.WriteSQLstatementstocreatethecorrespondingrelationsandcaptureasmanyoftheconstraintsaspossible.Ifyoucannotcapturesomeconstraints,explainwhy.
AnswerThefollowingSQLstatementscreatethecorrespondingrelations.
CREATETABLEEmployees(ssnCHAR(10),
salINTEGER,
phoneCHAR(13),
PRIMARYKEY(ssn))
CREATETABLEDepartments(dnoINTEGER,
budgetINTEGER,
dnameCHAR(20),
PRIMARYKEY(dno))
CREATETABLEWorksin(ssnCHAR(10),
dnoINTEGER,
PRIMARYKEY(ssn,dno),
FOREIGNKEY(ssn)REFERENCESEmployees,
FOREIGNKEY(dno)REFERENCESDepartments)
CREATETABLEManages(ssnCHAR(10),
dnoINTEGER,
PRIMARYKEY(dno),
FOREIGNKEY(ssn)REFERENCESEmployees,
FOREIGNKEY(dno)REFERENCESDepartments)
CREATETABLEDependents(ssnCHAR(10),
nameCHAR(10),
ageINTEGER,
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,fid:
integer)
Enrolled(snum:
integer,cname:
string)
Faculty(fid:
integer,fname:
string,deptid:
integer)
Themeaningoftheserelationsisstraightforward;forexample,Enrolledhasonerecordperstudent-classpairsuchthatthestudentisenrolledintheclass.
WritethefollowingqueriesinSQL.Noduplicatesshouldbeprintedinanyoftheanswers.
1).Findthenamesoffacultymembersforwhomthecombinedenrollmentofthecoursesthattheyteachislessthanfive
2).Foreachlevel,printthelevelandtheaverageageofstudentsforthatlevel.
3).ForalllevelsexceptJR,printthelevelandtheaverageageofstudentsforthatlevel.
4).ForeachfacultymemberthathastaughtclassesonlyinroomR128,printthefacultymember’snameandthetotalnumberofclassessheorhehastaught.
5).Findthenamesofstudentsenrolledinthemaximumnumberofclasses
6).Findthenamesofstudentsnotenrolledinanyclass.
Anwser:
1.SELECTDISTINCTF.fname
FROMFacultyF
WHERE5>(SELECTCOUNT(E.snum)
FROMClassC,EnrolledE
WHEREC.name=E.cname
ANDC.fid=F.fid)
2.SELECTS.level,AVG(S.age)
FROMStudentS
GROUPBYS.level
3.SELECTS.level,AVG(S.age)
FROMStudentS
WHERES.level<>‘JR’
GROUPBYS.level
4.SELECTF.fname,COUNT(*)ASCourseCount
FROMFacultyF,ClassC
WHEREF.fid=C.fid
GROUPBYF.fid,F.fname
HAVINGEVERY(C.room=‘R128’)
5.SELECTDISTINCTS.sname
FROMStudentS
WHERES.snumIN(SELECTE.snum
FROMEnrolledE
GROUPBYE.snum
HAVINGCOUNT(*)>=ALL(SELECTCOUNT(*)
FROMEnrolledE2
GROUPBYE2.snum))
6.SELECTDISTINCTS.sname
FROMStudentS
WHERES.snumNOTIN(SELECTE.snum
FROMEnrolledE)
第三套试卷
1.Explainthefollowingtermsbriefly:
attribute,domain,entity,relationship,one-to-manyrelationship,many-to-manyrelationship.
1.属性是实体集中每个成员具有的描述性性质;
2.域在文件系统中,有时也称做“字段”,是指数据中不可再分的基本单元。
一个域包含一个值。
3.实体是现实世界中可区别于其他对象的“事件”或“物体”。
每个实体都有一组属性,其中一部分属性的取值可以唯一标识一个实体;
4.联系是多个实体间的相互关联。
5.一对多来关系,A中的一个实体可以和B中的任意数目实体相联系,而B中的一个实体至多同A中的一个实体相联系。
6.多对多关系,A中的一个实体可以和B中的任意数目实体相联系,而B中的一个实体也可以同A中的任意数目实体相联系。
2.GiventworelationsR1andR2,whereR1containsN1tuples,R2containsN2tuples,andN2>N1>0,givetheminimumandmaximumpossiblesizes(in
tuples)fortheresultingrelationproducedbyeachofthefollowingrelationalalgebra
expressions.Ineachcase,stateanyassumptionsabouttheschemasforR1andR2
neededtomaketheexpressionmeaningful:
(1)R1∪R2,
(2)R1∩R2,(3)R1−R2,(4)R1×R2,(5)σa=5(R1),(6)πa(R1),
3.NotownRecordshasdecidedtostoreinformationaboutmusicianswho(资料)
4.ConsidertheNotowndatabasefromExercise3.Youhavedecided
torecommendthatNotownusearelationaldatabasesystemtostorecompanydata.
ShowtheSQLstatementsforcreatingrelationscorrespondingtotheentitysetsand
relationshipsetsinyourdesign.IdentifyanyconstraintsintheERdiagramthatyou
areunabletocaptureintheSQLstatementsandbrieflyexplainwhyyoucouldnot
expressthem.
AnswerThefollowingSQLstatementscreatethecorrespondingrelations.
1.CREATETABLEMusicians(ssnCHAR(10),
nameCHAR(30),
PRIMARYKEY(ssn))
2.CREATETABLEInstruments(instrIdCHAR(10),
dnameCHAR(30),
keyCHAR(5),
PRIMARYKEY(instrId))
3.CREATETABLEPlays(ssnCHAR(10),
instrIdINTEGER,
PRIMARYKEY(ssn,instrId),
FOREIGNKEY(ssn)REFERENCESMusicians,
FOREIGNKEY(instrId)REFERENCESInstruments)
4.CREATETABLESongsAppears(songIdINTEGER,
authorCHAR(30),
titleCHAR(30),
albumIdentifierINTEGERNOTNULL,
PRIMARYKEY(songId),
FOREIGNKEY(albumIdentifier)
ReferencesAlbumProducer)
5.CREATETABLETelephoneHome(phoneCHAR(11),
addressCHAR(30),
PRIMARYKEY(phone),
FOREIGNKEY(address)REFERENCESPlace,
6.CREATETABLELives(ssnCHAR(10),
phoneCHAR(11),
addressCHAR(30),
PRIMARYKEY(ssn,address),
FOREIGNKEY(phone,address)
ReferencesTelephoneHome,
FOREIGNKEY(ssn)REFERENCESMusicians)
7.CREATETABLEPlace(addressCHAR(30))
8.CREATETABLEPerform(songIdINTEGER,
ssnCHAR(10),
PRIMARYKEY(ssn,songId),
FOREIGNKEY(songId)REFERENCESSongs,
FOREIGNKEY(ssn)REFERENCESMusicians)
9.CREATETABLEAlbumProducer(albumIdentifierINTEGER,
ssnCHAR(10),
copyrightDateDATE,
speedINTEGER,
titleCHAR(30),
PRIMARYKEY(albumIdentifier),
FOREIGNKEY(ssn)REFERENCESMusicians)
5.Considerthefollowingschema:
Suppliers(sid:
integer,sname:
string,address:
string)
Parts(pid:
integer,pname:
string,color:
string)
Catalog(sid:
integer,pid:
integer,cost:
real)
TheCatalogrelationliststhepriceschargedforpartsbySuppliers.Writethefollowing
queriesinSQL:
1.Findthepnamesofpartsforwhichthereissomesupplier.
2.Findthesnamesofsupplierswhosupplyeverypart.
3.Findthesnamesofsupplierswhosupplyeveryredpart.
4.FindthepnamesofpartssuppliedbyAcmeWidgetSuppliersandnooneelse.
5.Findthesidsofsupplierswhochargemoreforsomepartthantheaveragecostof
thatpart(averagedoverallthesupplierswhosupplythatpart).
6.Foreachpart,findthesnameofthesupplierwhochargesthemostforthatpart.
Answer:
1.SELECTDISTINCTP.pname
FROMPartsP,CatalogC
WHEREP.pid=C.pid
2.SELECTS.sname
FROMSuppliersS
WHERENOTEXISTS((SELECTP.pid
FROMPartsP)
EXCEPT
(SELECTC.pid
FROMCatalogC
WHEREC.sid=S.sid))
3.SELECTS.sname
FROMSuppliersS
WHERENOTEXISTS((SELECTP.pid
FROMPartsP
WHEREP.color=‘Red’)
EXCEPT
(SELECTC.pid
FROMCatalogC,PartsP
WHEREC.sid=S.sidAND
C.pid=P.pidANDP.color=‘Red’))
4.SELECTP.pname
FROMPartsP,CatalogC,SuppliersS
WHEREP.pid=C.pidANDC.sid=S.sid
ANDS.sname=‘AcmeWidgetSuppliers’
ANDNOTEXISTS(SELECT*
FROMCatalogC1,SuppliersS1
WHEREP.pid=C1.pidANDC1.sid=S1.sidAND
S1.sname<>‘AcmeWidgetSuppliers’)
5.SELECTDISTINCTC.sid
FROMCatalogC
WHEREC.cost>(SELECTAVG(C1.cost)
FROMCatalogC1
WHEREC1.pid=C.pid)
6.SELECTP.pid,S.sname
FROMPartsP,SuppliersS,CatalogC
WHEREC.pid=P.pid
ANDC.sid=S.sid
ANDC.cost=(SELECTMAX(C1.cost)
FROMCatalogC1
WHEREC1.pid=P.pid)
6.Foreachpart,findthesnameofthesupplierwhoch
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 题库 答案