ImageVerifierCode 换一换
格式:DOCX , 页数:38 ,大小:410.99KB ,
资源ID:8583046      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8583046.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据库大题的答案.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据库大题的答案.docx

1、数据库大题的答案第一套试卷8. Consider the following information about a university database:Professors have an SSN, a name, an age, a rank, and a research specialty.Projects have a project number, a sponsor name (e.g., NSF), a starting date, an ending date, and a budget.Graduate students have an SSN, a name, an

2、age, and a degree program (e.g., M.S. or Ph.D.).Each project is managed by one professor (known as the projects principal investigator).Each project is worked on by one or more professors (known as the projects co-investigators).Professors can manage and/or work on multiple projects.Each project is

3、worked on by one or more graduate students (known as the projects research assistants).When graduate students work on a project, a professor must supervise their work on the project. Graduate students can work on multiple projects, in which case they will have a (potentially different) supervisor fo

4、r each one.Departments have a department number, a department name, and a main office.Departments have a professor (known as the chairman) who runs the department.Professors work in one or more departments, and for each department that they work in, a time percentage is associated with their job.Gra

5、duate students have one major department in which they are working on their degree.Each graduate student has another, more senior graduate student (known as a student advisor) who advises him or her on what courses to take.Design and draw an ER diagram that captures the information about the univers

6、ity.Use only the basic ER model here; that is, entities, relationships, and attributes. Be sure to indicate any key and participation constraints.9. Consider the university database from Exercise 8 and the ER diagram you designed. Write SQL statements to create the corresponding relations and captur

7、e as many of the constraints as possible. If you cannot capture some constraints, explain why.Answer:1. create table professors ( prof_ssn char(10),name char(64),age integer,rank integer,speciality char(64),primary key (prof ssn) )2. create table depts ( dno integer,dname char(64),office char(10),pr

8、imary key (dno) )3. create table runs ( dno integer,prof_ssn char(10),primary key ( dno, prof ssn),foreign key (prof ssn) references professors,foreign key (dno) references depts )4. create table work dept ( dno integer,prof_ssn char(10),pc_ time integer,primary key (dno, prof_ssn),foreign key (prof

9、_ssn) references professors ,foreign key (dno) references depts )observe that we would need check constraints or assertions in sql to enforce the rule that professors work in at least one department.5. create table project ( pid integer,sponsor char(32),start date char(20),end date char(20),budget f

10、loat,primary key (pid) )6. create table graduates ( grad ssn char(10),age integer,name char(64),deg prog char(32),major integer,primary key (grad ssn),foreign key (major) references depts )note that the major table is not necessary since each graduate has only one majorand so this can be an attribut

11、e in the graduates table.7. create table advisor ( senior ssn char(10),grad ssn char(10),primary key (senior ssn, grad ssn),foreign key (senior ssn) references graduates ,foreign key (grad ssn) references graduates )8. create table manages ( pid integer,prof ssn char(10),primary key (pid, prof ssn),

12、foreign key (prof ssn) references professors,foreign key (pid) references projects )9. create table work in ( pid integer,prof ssn char(10),primary key (pid, prof ssn),foreign key (prof ssn) references professors ,foreign key (pid) references projects )observe that we cannot enforce the participatio

13、n constraint for projects in thework in table without check constraints or assertions in sql.10. create table supervises ( prof ssn char(10),grad ssn char(10),pid integer,primary key (prof ssn, grad ssn, pid),foreign key (prof ssn) references professors(prof ssn),foreign key (grad ssn) references gr

14、aduates(grad ssn),foreign key (pid) references projects(pid) )Note that we do not need an explicit(明确的) table for the Work Proj relation since everytime a Graduate works on a Project, he or she must have a Supervisor.10. Consider the following relations:Student(snum: integer, sname: string, major: s

15、tring, level: string, age: integer)Class(name: string, meets at: string, room: string, d: integer)Enrolled(snum: integer,ame: string)Faculty(d: integer, fname: string, deptid: integer)The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair such

16、that the student is enrolled in the class.Write the following queries in SQL. No duplicates should be printed in any of the answers.1. Find the names of all Juniors (level = JR) who are enrolled in a class taught by I. Teach.2. Find the age of the oldest student who is either a History major or enro

17、lled in a course taught by I. Teach.3. Find the names of all classes that either meet in room R128 or have ve or more students enrolled.4. Find the names of all students who are enrolled in two classes that meet at the same time.5. Find the names of faculty members who teach in every room in which s

18、ome class is taught.The answers are given below:1. select distinct s.snamefrom student s, class c, enrolled e, faculty fwhere s.snum = e.snum and ame = c.name and c.d = f.d andf.fname = i.teach and s.level = jr2. select max(s.age)from student swhere (s.major = history)or s.snum in (select e.snum fro

19、m class c, enrolled e, faculty fwhere ame = c.name and c.d = f.dand f.fname = i.teach )3. select c.namefrom class cwhere c.room = r128or c.name in (select amefrom enrolled egroup by amehaving count (*) =5)4. select distinct s.snamefrom student swhere s.snum in (select e1.snumfrom enrolled e1, enroll

20、ed e2, class c1, class c2where e1.snum = e2.snum and ame ameand ame = c1.nameand ame = c2.name and c1.meets at = c2.meets at)5. select distinct f.fnamefrom faculty fwhere not exists ( select *from class c )except(selectc1.roomfrom class c1where c1.d = f.d )=第二套试卷 6 A company database needs to store

21、information about employees (identied by ssn,with salary and phone as attributes), departments (identied by dno, with dname and budget as attributes), and children of employees (with name and age as attributes). Employees work in departments; each department is managed by an employee; a child must b

22、e identied uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. We are not interested in information about a child once the parent leaves the company.Draw an ER diagram that captures this information.7 Consider the scenario from Exercise

23、6, where you designed an ER diagram for a company database. Write SQL statements to create the corresponding relations and capture as many of the constraints as possible. If you cannot capture some constraints, explain why.answer:the following sql statements create the corresponding relations.create

24、 table employees ( ssn char(10),sal integer,phone char(13),primary key (ssn) )create table departments ( dno integer,budget integer,dname char(20),primary key (dno) )create table works in ( ssn char(10),dno integer,primary key (ssn, dno),foreign key (ssn) references employees,foreign key (dno) refer

25、ences departments)create table manages ( ssn char(10),dno integer,primary key (dno),foreign key (ssn) references employees,foreign key (dno) references departments)create table dependents (ssn char(10),name char(10),age integer,primary key (ssn, name),foreign key (ssn) references employees,on delete

26、 cascade )8.Consider the following relations:Student(snum: integer, sname: string, major: string, level: string, age: integer)Class(name: string, meets at: string, room: string, d: integer)Enrolled(snum: integer,ame: string)Faculty(d: integer, fname: string, deptid: integer)The meaning of these rela

27、tions is straightforward; for example, Enrolled has one record per student-class pair such that the student is enrolled in the class.Write the following queries in SQL. No duplicates should be printed in any of the answers.1). Find the names of faculty members for whom the combined enrollment of the

28、 courses that they teach is less than ve.2). For each level, print the level and the average age of students for that level.3). For all levels except JR, print the level and the average age of students for that level.4). For each faculty member that has taught classes only in room R128, print the fa

29、culty members name and the total number of classes she or he has taught.5). Find the names of students enrolled in the maximum number of classes.6). Find the names of students not enrolled in any class.1. select distinct f.fnamefrom faculty fwhere 5 (select count (e.snum)from class c, enrolled ewher

30、e c.name = ame and c.d = f.d)2. select s.level, avg(s.age)from student sgroup by s.level3. select s.level, avg(s.age)from student swhere s.level jrgroup by s.level4. select f.fname, count(*) as coursecountfrom faculty f, class cwhere f.d = c.dgroup by f.d, f.fnamehaving every ( c.room = r128 )5. sel

31、ect distinct s.snamefrom student swhere s.snum in (select e.snumfrom enrolled egroup by amehaving count (*) = all (select count (*)from enrolled e2group by ame )6. select distinct s.snamefrom student swhere s.snum not in (select e.snumfrom enrolled e )第三套试卷2. Given two relations R1and R2, where R1 contains N1 tuples, R2contains N2 tuples, and N2 N1 0, give the minimum and maximum possible sizes (intuples) for the resulti

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

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