




已阅读5页,还剩17页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1.8 习题:1.(1) 关系型数据库管理系统,简称 RDBMS。是在E.F.Codd博士发表的论文大规模共享数据银行的关系型模型基础上设计出来的。它通过数据、关系和对数据的约束三者组成的数据模型来存放和管理数据。RDBMS 是 SQL 的基础,同样也是所有现代数据库系统的基础。(2) 在关系型数据库中,标准二维表是基本的数据存储单元,里边存储了实体的属性和实体间的关系。2. 关系型数据库中,表与表之间包括的三种关系是:一对一、一对多和多对多。(1) 一对一:有两个表,表A和表B。表A中的一条记录在表B中有一条记录与之对应。反过来,表B中的一条记录在表A中也仅有一条记录与之对应。(2) 一对多:有两个表,表A和表B。表A中的一条记录在表B中有多条记录与之对应。反过来,表B中的一条记录在表A中仅有一条记录与之对应。(3) 多对多:有两个表,表A和表B。表A中的一条记录在表B中有多条记录与之对应。反过来,表B中的一条记录在表A中也有多条记录与之对应。3. Oracle 10g提供了四个版本,分别是:Oracle 10g 标准版1、Oracle 10g 标准版、Oracle 10g 企业版、Oracle 10g 个人版。4.(1) 客户机/服务器结构:简称C/S结构,是软件系统的一种体系结构。数据库和数据库管理系统运行在服务器端,各种Oracle管理工具运行在客户机上,二者通过SQL*NET进行通信。(2) 浏览器/服务器结构:简称B/S结构,是随着Web技术兴起后的一种新型软件系统结构。它通常分为三层:数据库服务器,用来存储和管理数据库;应用程序服务器,与数据库服务器进行交互完成各种数据处理工作;客户端浏览器,与应用程序服务器进行交互,负责提交数据处理请求并获得和显示结果。5.(1) SYS:该用户被默认创建并授予DBA角色,它是Oracle数据库中权限最大的管理员账号。数据库中所有数据字典的基本表和视图都被存储在SYS的方案中,这些基本表和视图对于Oracle数据库的操作非常重要。为了维护数据字典的正确性和完整性,SYS方案中的表只能由系统维护,不能被任何用户或数据库管理员修改,而且任何用户不能在SYS方案中创建表。(2) SYSTEM:被默认创建并授予DBA角色权限仅次于SYS。该用户创建和管理数据库中可显示管理信息的表或视图,以及被Oracle数据库应用和工具使用的各种数据库对象。 (3) SYSMAN:该用户是企业管理的超级管理员账号,该账号能够创建和修改其他管理员账号,同时也能管理数据库实例。(4) DBSNMP:是Oracle数据库中用于智能代理(Intelligent Agent)的用户,用来监控和管理数据库相关性能。如果停止该用户,则无法提取相关的数据库信息。6.(1) 方法一:点击“开始”“程序” “Oracle - ”“Application Development”“SQL Plus” 进入Windows环境下的图形窗口(2) 方法二:点击“开始”“运行”输入“cmd命令”进入DOS环境下执行SQLPLUS命令也可以打开SQL*Plus工具。(3) 方式三:在IE浏览器地址栏中输入http:/主机名:端口号/isqlplus | http:/主机IP地址:端口号/isqlplus2.6 习题一、 填空题1. 数据、日志、控制、初始化参数 数据 控制 初始化参数2. 表空间、段、盘区、数据块 盘区 数据块3. 数据 段 盘区4. 用户进程 服务进程 后台进程 用户进程 服务进程5. 数据 重做日志6. 修改过的数据 数据文件7. 重做日志缓冲区内的日志 重做日志8. 日志条目 归档日志设备 归档9. 共享服务器 专有服务器 共享服务器 共享服务器二、 简答题1. Oracle数据库的物理存储结构式从物理组成的角度分析一个数据库在存储介质上的实际构成,它是由操作系统组织和管理的,是Oracle数据库的外部存储结构。(1) 数据文件:数据文件时Oracle数据库用来存储各种数据的地方,如表中的记录、索引数据、系统数据和临时数据等。(2) 日志文件:在Oracle中,日志文件记录了用户对数据的修改信息(如增加、删除、修改),名字通常为READ*.LOG格式。(3) 控制文件:控制文件时Oracle数据库的物理文件之一,它是一个很小的二进制文件,记录了数据库的名称、数据文件和连击日志文件的名称及位置、当前的日志序列号、表空间等信息。(4) 参数文件:参数文件中记录着数据库名称、控制文件的路径、SGA的内存结构、可选的Oracle特性和后台进程的配置参数等信息。2.(1) Oracle数据库逻辑存储结构是Oracle数据库创建后利用逻辑概念来描述数据库内部数据的组织和管理形式。包括表空间、段、区和块四种。(2) 表空间和数据文件的关系:数据库中的一个表空间至少包含一个或多个数据文件,而一个数据文件只能属于一个表空间。这种关联实现了数据库的逻辑存储结构和物理存储结构的统一。3.(1) 数据库实例是用户访问数据库的中间层,是使用数据库的手段,它为用户访问数据库提供了必要的内存空间和多个Oracle进程,它是动态的、临时的。一个Oracle实例由内存空间和Oracle进程两部分组成。(2) 数据库和数据库实例是相辅相成、缺一不可的。如果只有数据库的物理文件,只能说明有数据被存储在数据库中,但是无法直接访问。如果只有数据库实例,说明为数据库的使用做好了准备、可以访问数据库,但不知道要操作的数据在哪里。4.(1) 客户端配置a) sqlnet.ora文件用于指定数据库连接账号的验证方式以及连接字符串的解析方式,也就是说通过该文件决定怎样查找一个连接中出现的连接字符串的定义。b) tnsnames.ora文件时Oracle客户端的另一个重要文件,用来定义客户端连接远程服务器时的主机字符串。(2) 服务器端配置一、 listener.ora文件作用于Oracle数据库服务器端,是Oracle监听服务的配置文件。当客户端向服务器提交连接请求时,由监听服务接受并对连接账号进行有效验证,验证通过后将用户进程交给服务进程处理。若该文件被破坏,将影响监听服务的正常使用。3.5 习题一、 选择题1. C 2. C 3. B二、 简答题1. 一个方案只能被一个数据库用户拥有,并且方案名称与这个用户的名称相同。创建新用户时系统自动创建该用户的方案。数据库的每一个用户都拥有一个唯一的方案。该用户创建的方案对象默认被保存在自己的方案中。2. CREATE USER创建新用户命令:(1) USER-NAME :新创建的用户名称。(2) PASSWORD:为新用户制定密码。(3) DEFAULT TABLESPACE: 为新用户指定默认表空间。用来储存该用户创建的方案对象。(4) TEMPORARY TABLESPACE: 为用户指定临时表空间,存储操作过程中产生的临时数据。(5) QUOAT: 为新用户指定磁盘配额,表示该用户在指定的空间中可以占用的最大磁盘空间。(6) UNLIMITED: 表示该用户可以使用无限大的空间。(7) PROFILE: 指定新用户使用的配置文件。(8) PASSWORD expire:表示新用户密码过期,登陆后需要给出新密码。(9) ACCOUNT lock/unlock : 表示用户加锁/解锁状态。其中,用户名和密码是必须有的。三、 操作题1. CREATE USER ORA_TEMP IDENTIFIED BY TEM;2. ALTER USER ORA_TEMP IDENTIFIED BY ORA;3. ALTER USER ORA_TEMPACCOUNT LOCK;4.5 实验1.a) create table student(sno char(10) primary key,sname varchar2(8),sex char(2) default 男 check(sex=男 or sex=女),birthday date,sdept char(20);b) create table course(cno char(10) primary key,cname char(30) unique,ccredit number(3);c) create table score(sno char(10) references student(sno),cno char(10) references course(cno), grade number(3) check(grade=0 and gradesal;(4) select * from scott.emp where commsal*0.2;(5) select * from scott.emp where (deptno=10 and job=MANAGER) or (deptno=20 and job=CLERK);(6) select * from scott.emp where job not in(MANAGER,CLERK) and sal=2000;(7) select * from scott.emp where comm is not null;(8) select count(empno),avg(sal) from scott.emp;(9) select * from scott.emp where comm is null or comm100(10) select * from scott.emp where (sysdate-hiredate)/365=10;(12) select initcap(lower(ename) from scott.emp;(13) select * from scott.emp where length(ename)=6;(14) select * from scott.emp where ename not like %S%;(15) select * from scott.emp where ename like _M%;(16) select substr(ename,1,3) from scott.emp;(17) select replace(ename,s,S) from scott.emp;(18) select ename,hiredate from scott.emp order by hiredate;(19) select ename,job,sal from scott.emp order by job desc,sal asc;(20) select ename,extract(year from hiredate) as 年份,extract(month from hiredate) as 月份 from scott.emp order by 月份,年份;(21) select deptno,count(*),avg(sal),avg(sysdate-hiredate)/365) from scott.emp group by deptno;(22) select count(*),avg(sal) from scott.emp group by deptno;(23) select min(sal),job from scott.emp group by job having min(sal)3000;(24) select deptno,job,max(sal) from scott.emp group by deptno,job;(25) select count(*),avg(sal) from scott.emp group by job;5.6 习题1. C 2. A 3. A 4. A 5. C 6.A 7. B 8. C 9. A 10. B6.5 习题(1)select ename,dname from scott.emp t1 inner join scott.dept t2 on t1.deptno=t2.deptno where job=CLERK;(2)select * from scott.emp t1 right join scott.dept t2 on t1.deptno=t2.deptno(3)select * from scott.emp t1 left join scott.dept t2 on t1.deptno=t2.deptno(4)用子查询实现:select * from scott.emp where deptno=(select deptno from scott.dept where dname=SALES)用连接查询实现:select * from scott.emp t1 inner join scott.dept t2 on t1.deptno=t2.deptno where t2.dname=SALES;注意两种实现方式,在行和列上的变化。(5)简单自连接select t1.ename as 员工姓名,t2.ename 经理姓名 from scott.emp t1,scott.emp t2 where t1.mgr=t2.empno;(6)select t1.ename as 员工姓名,t2.ename 经理姓名 from scott.emp t1,scott.emp t2 where t1.mgr=t2.empno and t1.hiredatet2.hiredate(7)select t1.ename,t1.job,t1.deptno,t2.ename,t2.job,t2.deptno from scott.emp t1 cross join scott.emp t2 where t1.job=t2.job and t1.deptno t2.deptno(8)select t1.ename as 员工姓名,t2.ename 经理姓名 from scott.emp t1,scott.emp t2 where t1.mgr=t2.empno and t1.deptno=10;(9)select * from scott.emp where sal2500 union select * from scott.emp where job=ANALYST(10)select * from scott.emp where sal2500 intersectselect * from scott.emp where job=ANALYST(11)select * from scott.emp where sal2500minusselect * from scott.emp where job=ANALYST; (12)select * from scott.emp where sal(select avg(sal) from scott.emp)(13)select * from scott.emp where job=(select job from scott.emp where ename=SMITH)(14)select * from scott.emp where sal(select sal from scott.emp where ename=SMITH)(15)select ename,sal from scott.emp where salall(select sal from scott.emp where deptno=30)(16)select * from scott.emp where deptno in (select deptno from scott.emp group by deptno having count(*)5);(17)select * from scott.dept where deptno in(select deptno from scott.emp group by deptno having min(sal)2000)(18) 本题的关键是使用子查询作为数据源和查询的条件,可以从最里层的子查询开始理解select * from scott.dept where deptno in (select deptno from (select deptno,count(*) as 人数 from scott.emp group by deptno) where 人数=(select max(人数) from(select deptno,count(*) as 人数 from scott.emp group by deptno);(19)select * from scott.dept where deptno in(select deptno from scott.emp group by deptno having count(*)=1)(20)本题关键是使用相关子查询做条件select * from scott.emp e where sal(select avg(sal) from scott.emp group by deptno having e.deptno=deptno);(21) 本题关键是使用两个子查询的结果进行内连接查询select * from(select * from scott.emp e where sal(select avg(sal) from scott.emp group by deptno having e.deptno=deptno) t1 inner join(select avg(sal),deptno from scott.emp group by deptno) t2 on t1.deptno=t2.deptno);(22)select * from scott.dept where deptno in(select distinct deptno from scott.emp where empno in(select distinct mgr from scott.emp);(23)select * from scott.emp t1,scott.dept t2 where t1.deptno=t2.deptno and t1.deptno in(select deptno from scott.emp group by deptno having avg(sal)100;end loop;dbms_output.put_line(和是: |s);end;whlie循环实现:declarei number default 1;s number default 0;beginwhile i=100 loops:=s+i;i:=i+1;end loop;dbms_output.put_line(和是: |s);end;for循环实现:declares number default 0;beginfor i in 1.100 loops:=s+i;end loop;dbms_output.put_line(和是: |s);end;2.显示游标的for循环:declarecursor cur1 is select ename,sal from scott.emp;beginfor rec in cur1 loopdbms_output.put_line(rec.ename| |rec.sal);end loop;end;隐式游标的for循环:beginfor rec in (select ename,sal from scott.emp) loopdbms_output.put_line(rec.ename| |rec.sal);end loop;end;8.4 习题一、选择题1. A 2. C 3. B 4. D 5. A二、编程题1步骤一:授予system用户对scott.emp具有显示的查询权限sqlplus system/abcdefalter user scott account unlock;connect scott/tiger;grant select on emp to system;connect system/abcdef;步骤二:创建存储过程set serveroutput oncreate or replace procedure p1(id in scott
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 房车充电桩售卖合同范本
- 拆迁解除租赁合同协议书
- 房屋寄宿合同协议书模板
- 挖机开挖公路合同协议书
- 怎样作废竞业协议合同书
- 校区课程合作合同协议书
- 租赁合同第三方代签协议
- 楼梯施工安全合同协议书
- 托盘半成品销售合同范本
- 房屋承租居间的合同范本
- 老年女性子宫颈癌筛查中国专家共识(2024版)解读
- 安全防护设施培训
- 保洁投标书范本
- 二甲药剂科培训材料
- 医院科室副主任竞聘
- 《路由与交换技术》教学大纲
- 博士后研究报告(出站)
- 新人教版七年级上册生物全册教案(2024年秋季新版教材)
- 高标准农田改造提升建设项目投标方案(技术标)
- 关于天然气安全知识
- (高清版)DZT 0331-2020 地热资源评价方法及估算规程
评论
0/150
提交评论