数据库实验五:数据库设计实验

news2024/9/29 13:27:34

实验五 数据库设计实验

1.实验目的

​ 掌握数据库设计基本方法及数据库设计工具。

2.实验内容和要求

​ 掌握数据库设计基本步骤,包括数据库概念结构设计、逻辑结构设计,物理结构设计,数据库模式SQL语句生成。能够使用数据库设计工具进行数据库设计。

3.实验重点和难点

​ 实验重点:概念结构设计、逻辑结构设计。

​ 实验难点:逻辑结构设计。逻辑结构设计虽然可以按照一定的规则从概念结构转换来,但是由于概念结构通常比较抽象,较少考虑更多细节,因此转换而成的逻辑结构还需进一步调整和优化。逻辑结构承接概念结构和物理结构,处于核心地位,因而是数据库设计的重点。

4.实验过程

​ 设计一个教务信息系统的数据库。数据库包含院系信息,学生信息,教师信息,课程信息,学生选课信息,考试信息。其中,一个学生属于一个院系,可以选修多门课程。一个教师属于一个院系,可以任教多门课程,一门课程也可以有多个老师任教。一门课程有多个课程安排,可以有多场考试安排。

(1)数据库概念结构设计

​ 识别出学生,教师,院系,课程,考试,课程安排六个实体。每个实体的属性、码如下:

  • 学生Student:学号sno,姓名sname,性别ssex,年龄sage,班级class,院系编号dno。主码:学号sno。
  • 教师teacher:编号tno,姓名tname,性别tsex,年龄tage,院系dno,职称title。主码:编号tno。
  • 院系department:院系名depart_name,院系编号dno,院长编号dean_tno。主码:院系编号dno。
  • 课程course:课程号cno,课程名course_name,学时数hours,学分credit,类型type,开设院系dno。主码:课程号。
  • 课程安排course_arrangement:课程号cno,周次week,节次course_time,教室classroom。主码:课程号cno,周次week,节次course_time
  • 考试安排exam_arrangement:课程号cno,考试时间exam_time,考试时长hours,考试地点classroom。主码:课程号,考试地点。

​ 根据语义,分析实体之间的联系,确定实体之间一对一,一对多和多对多联系。

​ E-R图如下:
在这里插入图片描述

(2)数据库逻辑结构设计

​ 根据上述E-R图使用PowerDesigner设计数据库逻辑结构如下:

在这里插入图片描述

​ 共有8个关系,其中6个是实体,tc和sc分别是任教和选修这两个多对多的联系。关系的外键这里没有画出。

(3)数据库物理结构设计

​ 自动转换得到数据库物理结构:
在这里插入图片描述

​ 选择索引存取方法,数据库会自动为每个关系的主码建立索引。对于该系统,不需要建立其他索引。

(4)SQL语句生成

​ 由PowerDesigner生成的SQL语句如下:

​ student表:

if exists(select 1 from sys.sysforeignkey where role='fk_sc_s') then
    alter table sc
       delete foreign key fk_sc_s
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_sd') then
    alter table student
       delete foreign key fk_sd
end if;

if exists(
   select 1 from sys.systable 
   where table_name='student'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table student
end if;

/*==============================================================*/
/* Table: student                                               */
/*==============================================================*/
create table student 
(
   sno                  char(12)                       not null,
   sname                char(25)                       null,
   ssex                 char(2)                        null,
   sage                 smallint                       null,
   class                char(8)                        null,
   dno                  char(2)                        null,
   constraint PK_STUDENT primary key clustered (sno)
);

alter table student
   add constraint fk_sd foreign key (dno)
      references department (dno)
      on update restrict
      on delete restrict;

​ course表:

if exists(select 1 from sys.sysforeignkey where role='fk_cd') then
    alter table course
       delete foreign key fk_cd
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_ca_c') then
    alter table course_arrangement
       delete foreign key fk_ca_c
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_exam_c') then
    alter table exam_arrangement
       delete foreign key fk_exam_c
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_sc_c') then
    alter table sc
       delete foreign key fk_sc_c
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_tc_c') then
    alter table tc
       delete foreign key fk_tc_c
end if;

if exists(
   select 1 from sys.systable 
   where table_name='course'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table course
end if;

/*==============================================================*/
/* Table: course                                                */
/*==============================================================*/
create table course 
(
   cno                  char(8)                        not null,
   cname                char(25)                       null,
   hours                smallint                       null,
   credit               smallint                       null,
   type                 char(8)                        null,
   dno                  char(2)                        null,
   constraint PK_COURSE primary key clustered (cno)
);

alter table course
   add constraint fk_cd foreign key ()
      references department (dno)
      on update restrict
      on delete restrict;

​ teacher表:

if exists(select 1 from sys.sysforeignkey where role='fk_tc_t') then
    alter table tc
       delete foreign key fk_tc_t
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_td') then
    alter table teacher
       delete foreign key fk_td
end if;

if exists(
   select 1 from sys.systable 
   where table_name='teacher'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table teacher
end if;

/*==============================================================*/
/* Table: teacher                                               */
/*==============================================================*/
create table teacher 
(
   tno                  char(12)                       not null,
   tname                char(25)                       null,
   tsex                 char(2)                        null,
   tage                 smallint                       null,
   dno                  char(2)                        null,
   title                char(10)                       null,
   constraint PK_TEACHER primary key clustered (tno)
);

alter table teacher
   add constraint fk_td foreign key (dno)
      references department (dno)
      on update restrict
      on delete restrict;

​ department表:

if exists(select 1 from sys.sysforeignkey where role='fk_cd') then
    alter table course
       delete foreign key fk_cd
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_sd') then
    alter table student
       delete foreign key fk_sd
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_td') then
    alter table teacher
       delete foreign key fk_td
end if;

if exists(
   select 1 from sys.systable 
   where table_name='department'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table department
end if;

/*==============================================================*/
/* Table: department                                            */
/*==============================================================*/
create table department 
(
   dno                  char(2)                        not null,
   dame                 char(25)                       null,
   tno                  char(12)                       null,
   constraint PK_DEPARTMENT primary key clustered (dno)
);

​ course_arrangement:

if exists(select 1 from sys.sysforeignkey where role='fk_ca_c') then
    alter table course_arrangement
       delete foreign key fk_ca_c
end if;

if exists(
   select 1 from sys.systable 
   where table_name='course_arrangement'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table course_arrangement
end if;

/*==============================================================*/
/* Table: course_arrangement                                    */
/*==============================================================*/
create table course_arrangement 
(
   cno                  char(8)                        not null,
   week                 smallint                       not null,
   course_time          char(12)                       not null,
   classroom            char(10)                       null,
   constraint PK_COURSE_ARRANGEMENT primary key clustered (cno, week, course_time)
);

alter table course_arrangement
   add constraint fk_ca_c foreign key (cno)
      references course (cno)
      on update restrict
      on delete restrict;

​ exam_arrangement

if exists(select 1 from sys.sysforeignkey where role='fk_exam_c') then
    alter table exam_arrangement
       delete foreign key fk_exam_c
end if;

if exists(
   select 1 from sys.systable 
   where table_name='exam_arrangement'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table exam_arrangement
end if;

/*==============================================================*/
/* Table: exam_arrangement                                      */
/*==============================================================*/
create table exam_arrangement 
(
   cno                  char(8)                        not null,
   exam_time            char(10)                       null,
   classroom            char(10)                       not null,
   hour                 smallint                       null,
   constraint PK_EXAM_ARRANGEMENT primary key clustered (cno, classroom)
);

alter table exam_arrangement
   add constraint fk_exam_c foreign key (cno)
      references course (cno)
      on update restrict
      on delete restrict;

​ sc:

if exists(select 1 from sys.sysforeignkey where role='fk_sc_c') then
    alter table sc
       delete foreign key fk_sc_c
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_sc_s') then
    alter table sc
       delete foreign key fk_sc_s
end if;

if exists(
   select 1 from sys.systable 
   where table_name='sc'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table sc
end if;

/*==============================================================*/
/* Table: sc                                                    */
/*==============================================================*/
create table sc 
(
   sno                  char(12)                       not null,
   cno                  char(8)                        not null,
   grade                smallint                       null,
   constraint PK_SC primary key clustered (sno, cno)
);

alter table sc
   add constraint fk_sc_c foreign key (cno)
      references course (cno)
      on update restrict
      on delete restrict;

alter table sc
   add constraint fk_sc_s foreign key (sno)
      references student (sno)
      on update restrict
      on delete restrict;

​ tc:

if exists(select 1 from sys.sysforeignkey where role='fk_tc_c') then
    alter table tc
       delete foreign key fk_tc_c
end if;

if exists(select 1 from sys.sysforeignkey where role='fk_tc_t') then
    alter table tc
       delete foreign key fk_tc_t
end if;

if exists(
   select 1 from sys.systable 
   where table_name='tc'
     and table_type in ('BASE', 'GBL TEMP')
) then
    drop table tc
end if;

/*==============================================================*/
/* Table: tc                                                    */
/*==============================================================*/
create table tc 
(
   tno                  char(12)                       not null,
   cno                  char(8)                        not null,
   term                 char(8)                        not null,
   class                char(8)                        null,
   constraint PK_TC primary key clustered (tno, cno, term)
);

alter table tc
   add constraint fk_tc_c foreign key (cno)
      references course (cno)
      on update restrict
      on delete restrict;

alter table tc
   add constraint fk_tc_t foreign key (tno)
      references teacher (tno)
      on update restrict
      on delete restrict;

5.实验总结

​ 数据库的设计的基本步骤包括数据库概念结构设计、逻辑结构设计,物理结构设计。其中概念结构设计通常用E-R图表示。逻辑结构设计比较重要,需要从E-R图转换得到,并需要完成一些细节,进行调整优化。物理结构设计则需要完成存储路径的设计和存储结构的设计,需要根据实际情况进行设计。例如每个关系的存储结构,具体的数据类型和长度都要符合实际,同时尽量减小开销。使用类似PowerDesigner的工具可以辅助设计,方便的进行模型间的转化,并可以直接生成SQL语句,有必要掌握使用的基本方法。

5.实验总结

​ 数据库的设计的基本步骤包括数据库概念结构设计、逻辑结构设计,物理结构设计。其中概念结构设计通常用E-R图表示。逻辑结构设计比较重要,需要从E-R图转换得到,并需要完成一些细节,进行调整优化。物理结构设计则需要完成存储路径的设计和存储结构的设计,需要根据实际情况进行设计。例如每个关系的存储结构,具体的数据类型和长度都要符合实际,同时尽量减小开销。使用类似PowerDesigner的工具可以辅助设计,方便的进行模型间的转化,并可以直接生成SQL语句,有必要掌握使用的基本方法。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/96596.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ctf笔记:编码

常见编码 博客链接:https://www.blog.23day.site/articles/76 计算机中的数据都是按字节存储。一个字节(Byte)由8个二进制位组成(bit)。(组成范围是0~255(28))一个字节一共可以用来表示256种不同的状态,每一个状态对应一个符号,就…

推荐系统学习笔记-隐语义模型

由来 该算法最早在文本挖掘领域被提出,用于找到文本的隐含语义。 核心思想是通过隐含特征(latent factor) 联系用户兴趣和物品。 参数 f:隐向量维度,决定隐向量表达能力强弱 n:用户数 m:物品数 求解方法:…

ADI Blackfin DSP处理器-BF533的开发详解57:DSP控制ADV7180采集图像到LCD显示(含源码)

硬件准备 ADSP-EDU-BF533:BF533开发板 AD-HP530ICE:ADI DSP仿真器 软件准备 Visual DSP软件 硬件链接 代码实现功能 代码实现了采集一帧 720625 尺寸的 P 制 CVBS 信号源,以 YUYV422 的数据格式保存,通过 MDMA 将奇偶场数据交…

【轻松掌握C语言】文件操作

目录 一、为什么使用文件? 二、什么是文件? 1、程序文件 2、数据文件 3、文件名 三、文件操作 1、文件指针 2、文件打开与关闭 . 3、文件的顺序读写 4、文件的随机读写 5、文本文件和二进制文件 6、文件读取结束判定 四、文件缓冲区 一、…

C++ Reference: Standard C++ Library reference: Containers: map: map: rbegin

C官网参考链接&#xff1a;https://cplusplus.com/reference/map/map/rbegin/ 公有成员函数 <map> std::map::rbegin C98 reverse_iterator rbegin(); const_reverse_iterator rbegin() const; C11 reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin(…

这个大力神杯,梅西已足足等了16年,AI预测:阿根廷冠军

潘帕斯雄鹰和高卢雄鸡的决战&#xff0c;在三十多小时后即将上演。AI预测&#xff1a;胜率接近&#xff0c;阿根廷略高。 12月18日&#xff0c;卡塔尔世界杯总决赛将正式开战。 由卫冕军法国对上寻求队史第三冠的阿根廷&#xff0c;同时也是两位顶尖球星兼巴黎圣日耳曼队友梅…

LeetCode | 二叉树高频面试算法题汇总【速来】

小伙子&#xff0c;来给我✍棵树【LeetCode】144.二叉树的前序遍历C版本C语言版本&#xff08;递归算法展开图&#xff09;【LeetCode】94.二叉树的中序遍历C版本C语言版本【LeetCode】145.二叉树的后序遍历C版本C语言版本【LeetCode】102.二叉树的层序遍历DSF——深度优先搜索…

Linux 之centos7:一、Linux安装

Linux 之centos7 1.Linux简介 ​ Linux内核最初只是由芬兰人李纳斯托瓦兹&#xff08;Linus Torvalds&#xff09;在赫尔辛基大学上学时出于个人爱好而编写的。 ​ Linux是一套免费使用和自由传播的类Unix操作系统&#xff0c;是一个基于POSIX和UNIX的多用户、多任务、支持多…

C#,基于视频的目标识别算法(Moving Object Detection)的原理、挑战及其应用

本文概述了基于监控视频之连续帧信息的各种目标识别算法及其存在的问题与挑战&#xff0c;结合实际应用开发的工作&#xff0c;文中给出了实验性基于帧差算法和改进型背景算法的非人工智能目标识别算法的实际效果。 目标识别算法一直并将持续成为人工智能研究与应用的重点&…

交换机设备上的G口、F口、E口、S口区别是什么?一台交换机有哪些接口呢?每个接口都有哪些作用?

交换机设备上的G口、F口、E口、S口区别是什么? 一台交换机有哪些接口呢?每个接口都有哪些作用? 交换机的主要功能包括:学习功能、转发过滤和消除回路。 学习功能:以太网交换机知道连接到每个端口的设备的MAC地址,将该地址与相应的端口进行映射,并存储在交换机缓存的MA…

jsp+ssm计算机毕业设计大学生互助系统【附源码】

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; JSPSSM mybatis Maven等等组成&#xff0c;B/S模式 Mave…

点云 3D 目标检测 - VoxelNet(CVPR 2018)

点云 3D 目标检测 - VoxelNet&#xff08;CVPR 2018&#xff09;摘要1. 引言1.1 相关工作1.2 贡献2. VoxelNet2.1 VoxelNet架构2.1.1 特征学习网络2.1.2 卷积中层2.1.3 区域提案网络2.2 损失函数2.3 高效实施3. 训练详情3.1 网络详细信息3.2 数据增强4. 实验4.1 KITTI验证集评估…

【算法】动态规划 ⑧ ( 动态规划特点 )

文章目录一、动态规划特点1、求解类型2、方向性3、动态规划状态选择4、动态规划方程设计一、动态规划特点 1、求解类型 求解类型 : 动态规划 必须是求 最值 , 可行性 , 方案数 , 三者之一 , 如果求其它内容 , 则不能使用动态规划算法 ; 求最值 : 最大值 , 最小值 等 ; 大规模问…

[附源码]Node.js计算机毕业设计工资管理系统PPTExpress

项目运行 环境配置&#xff1a; Node.js最新版 Vscode Mysql5.7 HBuilderXNavicat11Vue。 项目技术&#xff1a; Express框架 Node.js Vue 等等组成&#xff0c;B/S模式 Vscode管理前后端分离等等。 环境需要 1.运行环境&#xff1a;最好是Nodejs最新版&#xff0c;我…

加入CSDN的第一百天,也是学C的第一百天

加入CSDN的一百天 1.学习总结 2.个人感悟 1.学习总结 学习c语言已经有100天&#xff0c;从一个初出茅庐的无知青年&#xff0c;敲出第一个hello world 都激动的不行&#xff0c;到现在&#xff1a; 常见的数据类型&#xff0c; 变量的命名方式&#xff0c; 变量的分类 到变…

[2022-12-17]神经网络与深度学习 hw9 - bptt

contentshw9 - Back Propagation Through Timetask1题目内容题目思路题目解答题目总结task2题目内容题目思路题目解答题目总结hw9 - Back Propagation Through Time task1 题目内容 推导RNN反向传播算法BPTT。 题目思路题目解答 首先我们要清楚RNN进行前向传播的过程&…

0. Canal 的安装和使用

我看过一场风景&#xff0c;后来我才知道&#xff0c;那是我人生中最美的一段时光。 我爱的人&#xff0c;爱我的人&#xff0c;都能度过这场新型感冒&#xff0c;那该多好。 Canal 的官网: https://github.com/alibaba/canal Canal 能干什么 为什么出现 Canal Canal 是阿里…

[ 数据结构 -- 手撕排序算法第二篇 ] 冒泡排序

文章目录前言一、常见的排序算法二、冒泡排序的实现2.1 基本思想2.2 单趟冒泡排序2.2.1 思路分析2.2.2 单趟代码实现三、冒泡排序的实现五、冒泡排序的时间复杂度5.1 最坏情况5.2 最好情况优化六、冒泡排序的特性总结总结前言 手撕排序算法第一篇&#xff1a;插入排序&#xf…

截止12.17 bitahub踩坑,mask无数次更改,lama代码的那些痛,羊了个羊,imwrite不生效

前面那篇跑出了STCN&#xff0c;倒是STCN熟悉了很多了 对bitahub&#xff0c;需要注意一个问题 要进ssh请用debug卡&#xff01;&#xff01;&#xff01;&#xff01; 要进ssh请用debug卡&#xff01;&#xff01;&#xff01;&#xff01; 要进ssh请用debug卡&#xff01;&…

AQS-semaphoreCyclicBarrierCountDownLatch源码学习

上文&#xff1a;jdk-BlockingQueue源码学习源码下载&#xff1a;https://gitee.com/hong99/jdk8semaphore&cyclicbarrier&CountDownLatch的介绍semaphore基础功能semaphore简称信号量&#xff0c;主要用于控制访问特定资源的线程数目&#xff0c;底层用的是AQS的状记s…