当前位置:文档之家› 《分布式数据库应用开发(Oracle)》第二学期期末试卷A参考答案

《分布式数据库应用开发(Oracle)》第二学期期末试卷A参考答案

2009-2010学年第二学期Array《分布式数据库应用开发(Oracle)》期末试卷(A卷)参考答案(开卷)总分:100分一、数据库分析(20分)E-R图与关系模型评分标准:一对实体与一个关系1分,共1*10分。

一条关系模式1分,共1*10分。

系部(系部编码,系部名称)专业(专业编码,专业名称)班级信息(班级编码,班级名称,专业编码,班主任)学生信息(学号,姓名,性别,班级编码,身份证号)教师信息(教工号,姓名,性别,系部编码,身份证号)课题信息(课题编码,课题名称,课题描述,指导教师编号,审核状态,可选人数,已选人数)学生选题(学号,课题编号,选题时间)上传资料(上传编码,上传内容,课题编号,学号,上传时间)毕设成绩(毕设成绩编码,学号,课题编码,指导教师评分,指导教师意见,答辩评分,答辩教师答辩意见,评阅评分,评阅教师,评阅意见,总分)审核信息(审核编码,毕设成绩编码,是否锁定)二、数据库设计(60分)(一)、创建高校毕业设计管理系统表空间和数据库(2+2+5,共9分)1.2分(名称和文件存放错误扣1分,其他扣一分)create temporary tablespace TempTBStempfile 'D:\oracle\product\10.2.0\oradata\orcl\tmptbs.dbf'size 30M reuseextent management local uniform size 16M;2.2分(名称和文件存放错误扣1分,其他扣一分)CREATE UNDO TABLESPACE UndoTBSDATAFILE 'D:\oracle\product\10.2.0\oradata\orcl\undotbs02.dbf' SIZE 2M REUSE; 3.5分(两个条件不满足扣1分)Create database PaperSysuser sys identified by orcluser system identified by orclcontrolfile reuselogfile group 1('redo01.log') size 10M,group 2('redo02.log') size 10M,maxlogfiles 10maxlogmembers 5maxdatafiles 100character set us7asciidatafile 'sys01.dbf' size 100m reuseextent management localdefault tablespace DefaultTBSdefautl temporary tablespace TempTBSundo tablespace UndoTBS;二、创建高校毕业设计管理系统相关表(1+1+2*5,共12分)Tb_Dept:(1分)create table Tb_Dept(DeptId varchar2(8) not null primary key,deptName varchar2(30) not null) ;Tb_Spec:(1分)create table Tb_Spec(SpecId varchar2(8) not null primary key,SpecName varchar2(30) not null);Tb_Teacher:(2分)(评分标准:约束与外键错误扣1分,其他扣1分)create table Tb_Teacher(TeacherId char(8) not null primary key,TeacherName varchar2(16) not null,sex char(1)CHECK(Sex in('M','F')),idCard char(18),status varchar2(16),DeptId varchar2(8) not null,foreign key(DeptId)references Tb_Dept(DeptId));Tb_Class(2分)(评分标准:约束与外键错误扣1分,其他扣1分)create table Tb_Class (ClassId char(7) not null primary key,ClassName char (20) not null,DeptId varchar2(8) not null,SpecId varchar2(8) not null,TeacherId char (8) not null,foreign key(DeptId)references Tb_Dept(DeptId),foreign key(SpecId)references Tb_Spec (SpecId),foreign key(TeacherId)references Tb_Teacher (TeacherId));或create table Tb_Class (ClassId char(7) not null primary key,ClassName char (20) not null,DeptId varchar2(8) not null references Tb_Dept(DeptId),SpecId varchar2(8) not null references Tb_Spec (SpecId),TeacherId char (8) not null references Tb_Teacher (TeacherId));Tb_Student(2分)(评分标准:约束与外键错误扣1分,其他扣1分)create table Tb_Student (StuId char(9) not null primary key,StuName char (8) not null,ClassId char(7) not null,Sex char(1)CHECK(Sex in('M','F')),Birthday date,SelectFlag char(1)CHECK(SelectFlag in('Y','N')),foreign key(ClassId)references Tb_Class(ClassId));Tb_CoursePaper(2分)(评分标准:约束与外键错误扣1分,其他扣1分)create table Tb_CoursePaper (PaperId number not null primary key,PaperName Varchar2(40) not null,TeacherId char(8) not null,maxNum number not null,selectNum number not null,checkFlag char(1) CHECK(checkFlag in('Y','N')),foreign key(TeacherId)references Tb_Teacher(TeacherId));Tb_SelectTitle:(2分)(评分标准:约束与外键错误扣1分,其他扣1分)create table Tb_SelectTitle (StuId char(9) not null,PaperId number not null,SelectDate date default sysdate,primary key(StuId,PaperId)) ;(三)、用SQL语句将下述数据插入到高校毕业设计管理系统相关表中(1*4+4,共8分)1、用SQL语句将下述数据插入到高校毕业设计管理系统相关表中(2*4,共8分)Tb_Teacher表(1分)Insert into Tb_Teacher values(‘12080801’,’王飞’,’F’,’50233697902182022’,’讲师’,‘08’);Tb_Class表(1分)Insert into Tb_Class values(‘S080801’,‘08软件1班’,‘08’,’05’,‘12080801’);Tb_Student表(1分)Insert into Tb_Student values(‘S0*******’, '宋涛','S080801','F',to_date('1988-3-24','yyyy-mm-dd'),'N');Tb_SelectTitle(1分)Insert into Tb_SelectTitle values(' S0*******', '1',' to_date('2010-3-24','yyyy-mm-dd'));向Tb_CoursePaper表中添加记录,代码如下:创建序列:(3分,两个条件不满足扣1分)create sequence seq_Paper Idminvalue 1nomaxvaluestart with 1increment by 1nocycle;Tb_CoursePaper表添加记录:(1分)Insert into Tb_CoursePaper values(seq_P aper Id.nextval , '课程网站的设计','12080801','3',’1’,'N');(四)、完成下列各题,写出SQL语句(2+2+1+4+10+6+6,共31分)( 1 )(2分)方法一:SELECT StuId,StuName FROM Tb_Student WHERE Birthday betweento_date( '1988-1-1','yyyy-mm-dd') and to_date( '1991-12-31','yyyy-mm-dd')order by StuId desc;方法二:SELECT StuId,StuName FROM Tb_Student WHERE (Birthday >= to_date( '1988-1-1','yyyy-mm-dd') and Birthday <= to_date( '1991-12-31','yyyy-mm-dd')) order by StuId desc;( 2 )(2分)Select sum(decode(StuChangeFlag,'Y',1,0)) 已选题总人数, sum(decode(StuChangeFlag,'N',1,0)) 未选题总人数from tb_student;或:Select sum(decode(StuChangeFlag, 'N',0,1)) 已选题总人数, sum(decode(StuChangeFlag'Y',0,1)) 未选题总人数from tb_student;( 3 )(1分)11( 4 ) (4分)CREATE ROLE StuSysRole IDENTIFIED BY myrolepwd;(1分)GRANT CONNECT TO StuSysRole;GRANT RESOURCE TO StuSysRole; (1分)CREATE USER StuSysUser IDENTIFIED BY UserPwd; (1分)GRANT UNLIMITED TABLESPACE TO StuSysUser; (1分)(5)(10分)评分细则:RMAN技术备份和恢复7分,五个步骤各1分,备份与恢复2分,闪回(Flashback)技术备份和恢复3分)1.修改日志模式:(1)以SYSDBA的身份登录,变更登录用户:connect sys/orcl as sysdba(2)关闭数据库:shutdown immediate(3)启动数据库,但不打开实例:startup mount(4)切换实例为归档日志模式了:alter database archivelog;2.创建表空间存放与RMAN相关的数据:alter database open;create tablespace rman_ts datafile 'D:\oracle\product\10.2.0\oradata\orcl\ rman_ts.dbf' size 200M;3.创建RMAN用户并授权创建RMAN用户rman,口令为rman,默认表空间为rman_ts,临时表空间为temp:create user rman identified by rman default tablespace rman_ts temporary tablespace temp;grant语句为用户授予权限:grant connect, recovery_catalog_owner, resource to rman ;4.创建恢复目录打开orcl数据库实例恢复管理器,恢复目录为rman:$rman catalog rman/rman target orcl使用rman_ts表空间创建恢复目录:RMAN>create catalog tablespace rman_ts;5.注册目标数据库register database命令对数据库进行注册:RMAN> register database;单独备份归档日志文件:RMAN> run {2> allocate channel dev1 type disk;3> backup archivelog all6> release channel dev1;7> }☐执行全数据库备份:RMAN> run {2> allocate channel dev1 type disk;3> backup database;4> release channel dev1;5> }☐执行全数据库恢复:RMAN> run {2> allocate channel dev1 type disk;3> restore database;4> release channel dev1;5> }☐单独恢复归档日志文件:RMAN> run {2> allocate channel dev1 type disk;3> restore archivelog all6> release channel dev1;7> }2.使用闪回(Flashback)技术备份和恢复数据库要设置某数据库为闪回数据库,必须以Mount方式启动数据库实例,并且数据库被设置为归档日志(Archivelog)模式。

相关主题