数据库设计与管理实验指导书

更新时间:2024-04-22 19:51:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

《数据库设计与管理》实验指导书

适用专业: 电子商务、信息管理与信息系统 学时数: 16 学 分: 编写人: 审定人:

实验1 Oracle的安装及其管理工具的使用

1、目的与要求

(1)掌握Oracle服务器的安装。

(2)掌握Oracle Net8 East Config工具

(3)掌握Storage Manager、Security Manager、SQL Worksheet工具 (4)对数据库及其对象有一个基本了解。 2、实验准备

(1)了解Oracle 8.05版本安装的软硬件要求。 (2)了解Oracle支持的身份验证模式。 (3) Oracle工具的主要功能。

(4)对数据库、表、数据库对象有一个基本了解。 (5)了解在SQL Worksheet中执行SQL语句的方法。 3、实验内容

1.安装Oracle 8.05。

根据软硬件环境,选择一个合适版本的Oracle 8.05。 2.完成下列操作

(1)在客户端建立服务名。

(2)在数据库服务器端建立用户表空间。

(3)在数据库服务器端建立用户,将用户与表空间关联,并赋给用户DBA的权限。

(4)以用户身份在SQL

Worksheet

工具中登入。

实验2 创建数据库和表

1、目的与要求

(1)了解Oracle数据库的逻辑结构和物理结构。 (2)了解表的结构特点。

(3)了解Oracle的基本数据类型。 (4)了解空值概念。

(5)学会在SQL Worksheet中创建表。 2、实验准备

(1) Oracle数据库服务器安装完毕,并能正常使用。

(2) 用户具有DBA权限。 (3) 悉创建表的方法

3、实验内容

创建用于企业管理的员工管理数据库,用户名为YGGL(学号), 以及员工的信息、部门信息以及员工薪水信息。包含下列3个表: (1)Employees:员工信息表。

(2)Departments:部门信息表。

(3)Salary:员工薪水情况表。

各表的结构分别如表1、表2和表3所示。

表1 Employees表结构 列 名 数据类型 长 度 是否允许为空 EmployeeID Char 6 × Name Varchar2 20 × Birthday DATE × Sex Number 1 × Address Varchar2 30 √ EmailAddress Varchar2 30 √ DepartmentID Char 3 × Zip Char 6 √ 表2 Departments表结构 列 名 数据类型 长 度 是否允许为空 DepartmentID Char 3 × DepartmentName Varchar2 20 × Note Varchar2 20 √ 表3 Salary 列 名 数据类型 长 度 是否允许为空 EmployeeID Char 6 × InCome Number (8,2) × OutCome Number (8,2) × 说 明 员工编号,主键 姓名 出生日期 性别 地址 电子邮件地址 部门号,外键 邮编 说 明 部门号,主键 部门姓名 备注 说 明 员工编号,主键 收入 支出 实验3表数据插入、修改、删除和查询

1、目的与要求

(1)学会在SQL WorkSheet中对数据库表进行插入、修改和删除数据操作。 (2)了解数据更新操作时要注意数据完整性。

(3)掌握Commit、Rollback对DMl、DDl语句的影响。 2、实验准备

(1)了解对表数据的插入、删除、修改都属于表数据的更新操作。

(2)掌握SQL中用于对表数据进行插入、修改和删除的命令分别是INSERT、UPDATE

和DELETE(或TRANCATE TABLE)。

(3)特别注意在执行插入、删除、修改等数据更新操作时,必须保证数据完整性。

3、实验内容

(1)在表Employees中加入如表4所示的记录。

(2)在表Departments中插入如表5所示的记录。

(3)在表Salary中插入如表6所示的记录。

(4)删除表Employees的第2、8行和Salary的第2、11行。注意进行删除操作

时,作为两表主键的EmployeeID的值,以保持数据完整性。

(5) 删除表Departments的第2行,同时也要删除表Employees的第2行。

(6)将表Employees中编号为020018的记录的部门号改为4。

编号 姓名 地址 000001 王林 A 010008 伍容华 B 020010 王向容 C 020018 李丽 D 102201 刘明 E 102208 朱俊 F 108991 钟敏 G 111006 张石兵 H 210678 林涛 I 302566 李玉珉 J 308759 叶凡 K 504209 陈林琳 L 表5 Departments表记录 编号 部门名称 备注 1 财务处 NULL 2 人力资源部 NULL 3 经理办公室 NULL 4 研发部 NULL 5 市场部 NULL

表6 Salary表记录 编号 收入 000001 2100.8 010008 1582.62 102201 2569.88 111006 1987.01 504209 2066.15 302566 2980.7 108991 3259.98 表4 Employees表记录 邮编 电话 电子邮件 210003 210001 210006 210002 210013 210004 210010 210008 210003 210018 210001 210002 部门号 2 1 1 1 5 5 3 5 3 4 4 4 出生日期 1956-1-23 1954-1-12 1964-1-12 1974-1-12 1944-5-12 1954-1-12 1959-7-12 1964-11-10 1954-11-10 1953-11-19 1951-10-16 1954-10-11 性别 1 1 1 0 1 1 0 1 1 1 1 0

支出 123.09 88.03 185.65 79.58 108.0 210.2 281.52 020010 020018 308759 210678 102208

2860.0 2347.68 2531.98 2240.0 1980.0 198.0 180.0 199.08 121.0 100.0 实验4 SQL编程

1、目的与要求

(1)掌握SELECT语句的基本语法。 (2)掌握子查询的表示。 (3)掌握连接查询的表示。 (4)掌握数据汇总的方法。

(5)掌握SELECT语句的GROUPBY子句的作用和使用方法。 (6)掌握SElECT语句的ORDERBY子句的作用和使用方法。

2、实验准备

(1)了解SELECT语句的基本语法格式。 (2)了解SELECT语句的执行方法。 (3)了解子查询的表示方法。 (4)了解连接查询的表示。 (5)了解数据汇总的方法。

(6)了解SELECT语句的GROUPBY子句的作用和使用方法。 (7)了解SELECT语句的ORDERBY子句的作用。

3、实验内容

(1)查每个员工的所有数据:select * from employees

(2)查询每个雇员的地址和电话:select address,phonenumber from employees

(3)查询EmployeeID为000001的雇员的地址和电话:select address

phonenumber employees where employeeid=‘000001‘

(4)查询Employees表中女雇员的地址和电话,使用AS子句将结果中各列的标题

分别指定为地址、电话:select address as 地址,phonenumber as 电话 from employees where sex=0

(5)计算每个雇员的实际收入:select employeeid,(income-outcome) as 实际

收入 from salary

(6)找出所有姓王的雇员的部门号:select departmentid form employees where

name like ‘王%‘

(7)找出所有收入在2000—3000元之间的雇员编号:select employeeid from

salary where income between 2000 and 3000

(8)查找在财务部工作的雇员阶情况:select * from employees where

departmentid=(select departmentid from departments where departmentname=’财务部’)

(9)查找财务部年龄不低于研发部雇员年龄的雇员的姓名:select name from

employees where departmentid in (select departmentid from departments where departmentname=’财务部’) and birthday >all(select birthday from employees where departmentid in (select departmentid from departments where departmentname=’研发部’))

(10) 查找比所有财务部的雇员收入都高的雇员的姓名:select name from

employees where employeeid in(select employeeid from salary where income>all(select income from salary where employeeid in (select employeeid from employees where departmentname=(select departmentid from departments where departmentname=’财务部’))))

(11) 查询每个雇员阶情况及其薪水时情况:select employees.*,salary.* from

employees,salary where employees.employeeid=salary.employeeid

(12) 查找财务部收入在2200元以上的雇员姓名及其薪水详情:select

name,income,outcome from employees ,salary,departments where employees.employeeid=salary.employeeed and employees.departmentid=departments.departmentid and departmentname=’财务部’ and income>2000

(13) 求财务部雇员的平均收入:select avg(income) as 财务部平均工资 from

salary where employeeid in (select employeeid from employees where departmentid=(select departmentid from departments where departmentname=’财务部’))

(14) 求财务部雇员的平均实际收入:select avg(income-outcome) as 求财务部

雇员的平均实际收入 from salary where employeeid in (select employeeid from employees where departmentid=(select departmentid from departments where departmentname=’财务部’))

(15) 求财务部雇员的总人数:select count(employeeid) from employees where

departmentid=(select departmentid from departments where departmentname=’财务部’)

(16) 求各部门的雇员数:select count(employeeid) from employees group by

departmentid

(17) 将各雇员阶情况按收入由低到高排列:select employees.*,salary.* from

employees,salary where employees.employeeid=salary.employeeid order by income

实验5 视图、存储过程

1、目的与要求

(1)掌握视图的创建和使用方法。 (2)掌握存储过程的使用方法。

2、实验准备

(1)了解视图的创建和使用方法。 (2)了解存储过程的使用方法。

3、实验内容

(1)根据表employees建Vemployees视图

(2)根据表departments建Vdepartments视图

(3)根据表salary建Vsalary视图

(4)添加职员记录的存储过程 (5)修改职员记录的存储过程 (6)删除职员记录的存储过程

本文来源:https://www.bwwdw.com/article/jhbp.html

Top