首页 > 其他分享 >实验报告

实验报告

时间:2023-04-22 22:00:37浏览次数:33  
标签:restrict null constraint CHAR key table 实验报告

数据库建模与查询设计

1.概念模型设计及逻辑模型设计描述

根据给定的应用需求和ER图参考,给出最终的ER图,并根据ER图进行逻辑模型转化,给出关系模式集合。
ER图:

手工逻辑模型转换:


2.数据建模工具的模型设计过程描述

使用工具 power desiger 根据实验附件步骤选择实体框以及关系线完成CDM的设计

选择对应的DBMS内核生成对应的PDM(因为在CDM阶段没有多对多关系属性的插入选项,故需要在此时插入对应的属性)。

选择生成DDL文件,并对部分SQL语句做调整,最终生成可用DDL语句:




/*==============================================================*/
/* Table: DanRen                                                */
/*==============================================================*/
create table DanRen (
   Eno                  CHAR(8)              not null,
   Pno                  CHAR(4)              not null,
   DRdate               DATE                 null,
   constraint PK_DANREN primary key (Eno, Pno)
);




/*==============================================================*/
/* Table: Have1                                                 */
/*==============================================================*/
create table Have1 (
   Dno                  CHAR(2)              not null,
   Rno                  CHAR(4)              not null,
   constraint PK_HAVE1 primary key (Dno, Rno)
);




/*==============================================================*/
/* Table: Have2                                                 */
/*==============================================================*/
create table Have2 (
   Dno                  CHAR(2)              not null,
   Pno                  CHAR(4)              not null,
   constraint PK_HAVE2 primary key (Dno, Pno)
);





/*==============================================================*/
/* Table: PinYong                                               */
/*==============================================================*/
create table PinYong (
   Eno                  CHAR(8)              not null,
   Rno                  CHAR(4)              not null,
   PYdate               DATE                 null,
   constraint PK_PINYONG primary key (Eno, Rno)
);


/*==============================================================*/
/* Table: department                                            */
/*==============================================================*/
create table department (
   Dno                  CHAR(2)              not null,
   dep_Dno              CHAR(2)              null,
   Dname                CHAR(20)             null,
   Dtype                CHAR(20)             null,
   Dman                 INT4                 null,
   constraint PK_DEPARTMENT primary key (Dno)
);


/*==============================================================*/
/* Table: empolyeer                                             */
/*==============================================================*/
create table empolyeer (
   Eno                  CHAR(8)              not null,
   Dno                  CHAR(2)              null,
   Ename                CHAR(20)             null,
   Epasswd              CHAR(12)             null,
   Esex                 CHAR(3)              null,
   Ebirth               DATE                 null,
   constraint PK_EMPOLYEER primary key (Eno)
);

/*==============================================================*/
/* Table: rank                                                  */
/*==============================================================*/
create table rank (
   Rno                  CHAR(4)              not null,
   Rname                CHAR(20)             null,
   constraint PK_RANK primary key (Rno)
);

/*==============================================================*/
/* Table: post                                                  */
/*==============================================================*/
create table post (
   Pno                  CHAR(4)              not null,
   Pname                CHAR(20)             null,
   constraint PK_POST primary key (Pno)
);



alter table DanRen
   add constraint FK_DANREN_DANREN_EMPOLYEE foreign key (Eno)
      references empolyeer (Eno)
      on delete restrict on update restrict;

alter table DanRen
   add constraint FK_DANREN_DANREN2_POST foreign key (Pno)
      references post (Pno)
      on delete restrict on update restrict;

alter table Have1
   add constraint FK_HAVE1_HAVE1_DEPARTME foreign key (Dno)
      references department (Dno)
      on delete restrict on update restrict;

alter table Have1
   add constraint FK_HAVE1_HAVE2_RANK foreign key (Rno)
      references rank (Rno)
      on delete restrict on update restrict;

alter table Have2
   add constraint FK_HAVE2_HAVE3_DEPARTME foreign key (Dno)
      references department (Dno)
      on delete restrict on update restrict;

alter table Have2
   add constraint FK_HAVE2_HAVE4_POST foreign key (Pno)
      references post (Pno)
      on delete restrict on update restrict;

alter table PinYong
   add constraint FK_PINYONG_PINYONG_EMPOLYEE foreign key (Eno)
      references empolyeer (Eno)
      on delete restrict on update restrict;

alter table PinYong
   add constraint FK_PINYONG_PINYONG2_RANK foreign key (Rno)
      references rank (Rno)
      on delete restrict on update restrict;

alter table department
   add constraint FK_DEPARTME_SUOSHU_DEPARTME foreign key (dep_Dno)
      references department (Dno)
      on delete restrict on update restrict;

alter table empolyeer
   add constraint FK_EMPOLYEE_BELONG_DEPARTME foreign key (Dno)
      references department (Dno)
      on delete restrict on update restrict;



3.数据库创建过程描述

参考华为的 openGauss 安装文件,首先在云端购买弹性云服务器

然后本地使用 ssh 连接到云主机,根据步骤下载安装openGauss

服务器打开 openGauss 服务,并使用 _Date Studio_连接数据库,并运行保存的DDL命令建立数据表

最终创建各表如下:
部门表

员工表

聘用表

任职表

拥有表1

拥有表2

职务表

职级表


4.数据库查询设计与实现描述

  • 查找员工中年龄最大的人的姓名以及编号
    • 代码:
      select ename,eno from empolyeer where ebirth IN (select min(ebirth) from empolyeer);
    • 查询结果
  • 查找张三的职务是什么
    • 代码:
      select pname from post where pno IN (select pno from danren where eno IN (select eno from empolyeer where ename = '张三'));
    • 查询结果
  • 查询财政部有哪些具体的职务
    • 代码:
      select post.*,have2.* from post,have2 where post.pno = have2.pno AND have2.dno IN (select dno from department where dname = '财政部');
    • 查询结果
  • 查询担任过一级科员的男性员工姓名
    • 代码:
      select ename from empolyeer where eno IN (select eno from pinyong where rno IN (select rno from rank where rname = '一级科员')) INTERSECT select ename from empolyeer where esex='男';
    • 查询结果

5.问题分析

  • 因时间属性都使用了Date类型,当时不清楚如何对该类型排序选择。
    解决:查询后发现Date适用于聚集函数,故选用min()函数对时间进行筛选。
  • CDM中找不到插入多对多关系的属性的选项
    解决:最终在生成的PDM中手动插入属性。

6.实验感想

此次试验主要是针对复杂查询的实践,通过自己对实际问题的模拟设计以及查询不仅能够对SQL的查询更加熟练,更是在模拟实际问题的过程中能够发现当前数据表设计的不合理情况,对ER图的设计更有另外的不同体会。整个实验过程是在实验室内完成,节奏紧凑,节省了课下的不少时间,希望老师能够继续这种实验的安排方式。

标签:restrict,null,constraint,CHAR,key,table,实验报告
From: https://www.cnblogs.com/RookieHacker1230/p/17344203.html

相关文章

  • 数据库应用实验一实验报告
    目录实验报告课程:数据库应用班级:2012姓名:郭幸坤学号:20201213实验名称:实验一实验日期:2023.4.15概念模型设计及逻辑模型设计描述ER图关系模式集合数据建模工具的模型设计过程描述物理模型逻辑模型概念模型数据库创建过程描述建立数据库表列表数据库查询设计与实现描述数据库内容......
  • UML时序图实验报告
    1,这是一张向我们直接展示了银行取款活动图,首先我们需要填写表单,其次需要输入密码,根据判断条件,检查密码的正误,密码错误直接结束,密码正确,根据用户的需求,如果取款则出款并结束,如果是计算利息,则执行打印清单操作,并结束。   2,这张图片展示了用户想要续借图书的时序图,这里的目......
  • Linux实验报告-上 海 开 放 大 学-指导: linux-1688
    上海开放大学实验名称:Linux操作系统安装配置简答题(直接打字回答在题目下方,仅完成4道题目的同学,最高30分。另外70分是加给自己搭建实验环境完成实验报告的同学):1、Linux和Windows系统有哪些不同之处?指导加VX:linux-16882、Linux系统的有哪些主要的发行版本?指导加VX:linux......
  • UML类图实验报告
    一:首先在我们更好的理解UML类图之前,我先用几个简单的小例子把UML类图所存在的关系给表达清楚-_-!1)第一个叫泛化,名字听起来很高级,也就是我们常说的继承,就像古代的皇帝快要驾崩了,需要指定皇子来继承王位,但“继承”可要比皇子继承皇位(单继承)要牛多了,他给人的印象就像是“一人得到。......
  • 高性能计算实验报告
    高性能计算实验报告第一部分实验介绍1.1实验基础需要使用slurm系统进行太原国家高算的资源调度,使用mpi进行并行计算。1.2实验目的及其意义本实验将利用mpi实现一个大数据量的排序算法(PSRS)。第二部分算法分析2.1算法介绍:正则采样排序PSRS的MPI算法如果注意到一个......
  • Exp4 恶意代码分析 实验报告—20201229赵斌
    Exp4恶意代码分析实验报告—20201229赵斌一、实验目标1.监控自己系统的运行状态,看有没有可疑的程序在运行。2.分析一个恶意软件,就分析Exp2或Exp3中生成后门软件;分析工具尽量使用原生指令或sysinternals,systracer套件。3.假定将来工作中你觉得自己的主机有问题,就可以用实验......
  • Exp3-免杀原理 实验报告—20201229赵斌
    免杀原理与实践基础问题回答Q1:杀软是如何检测出恶意代码的?(1)基于特征码的检测特征码是一段或多段数据,如果一个可执行文件(或其他运行的库、脚本等)包含这样的数据则被认为是恶意代码。AV软件厂商要做的就是尽量搜集最全的、最新的特征码库。所以杀毒软件的更新很重要。过时的特......
  • 实验报告
           ......
  • 20201326_exp2_后门原理与实践_实验报告
    20201326EXP2-后门原理与实践一、实验基础实验目的本次实验需要我们掌握后门的基础知识,学习使用nc实现Windows,Linux之间的后门连接,学习使用Metaspolit的msfvenom指令......
  • 实验报告1
     ......