ZUCC_数据库系统概论实验_实验三 使用PowerDesigner设计物理模型并转换为数据库对象

实验三 使用PowerDesigner设计物理模型并转换为数据库对象

课程名称 数据库系统概论实验
实验项目名称 实验三 使用PowerDesigner设计物理模型并转换为数据库对象

一、实验目的

  1. 掌握ER图向关系模式转换的方法;
  2. 使用PowerDesigner设计物理模型;
  3. 设置DSN;
  4. 通过物理模型生成数据库对象。

二、实验内容

  1. 将概念模型转换为物理模型
  2. 直接设计物理模型
  3. 设置DSN
  4. 在PowerDesigner中使用其自带工具,生成数据库对象

实验基础知识提要

物理模型(PDM):CDM反映了业务领域中信息之间的关系,它不依赖于物理实现。只有重要的业务信息才出现在CDM 中。PDM定义了模型的物理实现细节。例如,所选RDBMS的数据类型特征、索引定义、视图定义、存储过程定义、触发器定义等。

分析阶段的CDM转换成PDM后,便将抽象的实体、属性与关系,对应到实际数据库的数据表、字段、主键、外部索引键等内容。

PowerDesigner支持模型间的转换

ZUCC_数据库系统概论实验_实验三 使用PowerDesigner设计物理模型并转换为数据库对象_第1张图片

使用PowerDesigner进行数据库设计的基本过程:

ZUCC_数据库系统概论实验_实验三 使用PowerDesigner设计物理模型并转换为数据库对象_第2张图片

三、实验步骤

ER图向关系模式转化的基本原则:

  1. 一个实体型转化为一个独立的关系模式,实体的码就是关系的码
  2. 一个1:1联系可以转换为一个独立的关系模式,也可以与任意一端对应的关系模式合并
  3. 一个1:n联系可以转换为一个独立的关系模式,也可以与n端对应的关系模式合并
  4. 一个m:n联系可以转换为一个关系模式。
  5. 三个或三个以上实体间的一个多元联系可以转换为一个关系模式。
  6. 具有相同码的关系模式可合并。

将概念模型转换为物理模型

  • 打开*.cdm
  • 点击Tools-Generate Physical Data Model
  • 选择DBMS为MYSQL
  • 设定Name和Code
  • 生成PDM(Physical Data Model)
  • 鼠标右键—Properties—Preview
  • 将SQL内容全选—复制

将物理模型生成数据库

  • 打开Navicat for MySQL
  • 在本地服务器下新建数据库Course
  • 选中Course后,选择查询—新建查询
  • 将PowerDesigner中复制的SQL语句,粘贴到查询编辑器
  • 点击“运行”按钮,执行SQL语句
  • 查看运行情况
  • 观察左侧表的信息(需要刷新)

四、实验结果与分析

旅行社管理系统

drop table if exists Constitute;

drop table if exists Gudie;

drop table if exists LinesName;

drop table if exists Scenic;

drop table if exists Team;

/*==============================================================*/
/* Table: Constitute                                            */
/*==============================================================*/
create table Constitute
(
   Lines_id             varchar(10) not null,
   Scenic_id            varchar(10) not null,
   primary key (Lines_id, Scenic_id)
);

/*==============================================================*/
/* Table: Gudie                                                 */
/*==============================================================*/
create table Gudie
(
   Work_id              varchar(10) not null,
   Lines_id             varchar(10),
   Work_name            varchar(20),
   Grade                text,
   primary key (Work_id)
);

/*==============================================================*/
/* Table: LinesName                                             */
/*==============================================================*/
create table LinesName
(
   Lines_id             varchar(10) not null,
   Lines_name           varchar(20),
   Lines_describe       text,
   primary key (Lines_id)
);

/*==============================================================*/
/* Table: Scenic                                                */
/*==============================================================*/
create table Scenic
(
   Scenic_id            varchar(10) not null,
   Scenic_name          varchar(20),
   PlaceName            varchar(20),
   DescribeText         text,
   primary key (Scenic_id)
);

/*==============================================================*/
/* Table: Team                                                  */
/*==============================================================*/
create table Team
(
   Team_id              varchar(10) not null,
   Lines_id             varchar(10) not null,
   Team_number          int,
   Begin_data           date,
   End_data             date,
   primary key (Team_id)
);

alter table Constitute add constraint FK_Constitute foreign key (Lines_id)
      references LinesName (Lines_id) on delete restrict on update restrict;

alter table Constitute add constraint FK_Constitute2 foreign key (Scenic_id)
      references Scenic (Scenic_id) on delete restrict on update restrict;

alter table Gudie add constraint FK_Work foreign key (Lines_id)
      references LinesName (Lines_id) on delete restrict on update restrict;

alter table Team add constraint FK_Travel foreign key (Lines_id)
      references LinesName (Lines_id) on delete restrict on update restrict;

企业管理系统

drop table if exists Company;

drop table if exists Equipment;

drop table if exists Programme;

drop table if exists Supplier;

drop table if exists Workers;

/*==============================================================*/
/* Table: Company                                               */
/*==============================================================*/
create table Company
(
   Company_name         varchar(50) not null,
   Company_number       varchar(20) not null,
   primary key (Company_name)
);

/*==============================================================*/
/* Table: Equipment                                             */
/*==============================================================*/
create table Equipment
(
   Equipment_id         varchar(20) not null,
   Programme_name       varchar(50),
   Supplier_name        varchar(50) not null,
   Equipment_name       varchar(20) not null,
   Production_place     varchar(200) not null,
   primary key (Equipment_id)
);

/*==============================================================*/
/* Table: Programme                                             */
/*==============================================================*/
create table Programme
(
   Programme_name       varchar(50) not null,
   place                varchar(50),
   primary key (Programme_name)
);

/*==============================================================*/
/* Table: Supplier                                              */
/*==============================================================*/
create table Supplier
(
   Supplier_name        varchar(50) not null,
   Supplier_number      varchar(20) not null,
   primary key (Supplier_name)
);

/*==============================================================*/
/* Table: Workers                                               */
/*==============================================================*/
create table Workers
(
   Workers_id           varchar(10) not null,
   Programme_name       varchar(50) not null,
   Company_name         varchar(50) not null,
   Name                 varchar(20) not null,
   Gender               char(1) not null,
   primary key (Workers_id)
);

alter table Equipment add constraint FK_Run foreign key (Programme_name)
      references Programme (Programme_name) on delete restrict on update restrict;

alter table Equipment add constraint FK_Supply foreign key (Supplier_name)
      references Supplier (Supplier_name) on delete restrict on update restrict;

alter table Workers add constraint FK_Employ foreign key (Company_name)
      references Company (Company_name) on delete restrict on update restrict;

alter table Workers add constraint FK_Words foreign key (Programme_name)
      references Programme (Programme_name) on delete restrict on update restrict;

图书借阅管理系统

drop table if exists Borrow;

drop table if exists Borrower;

drop table if exists Libary;

drop table if exists Press_information;

/*==============================================================*/
/* Table: Borrow                                                */
/*==============================================================*/
create table Borrow
(
   Borrow_card_id       varchar(10) not null,
   Book_id              varchar(20) not null,
   Is_borrowring        bool not null,
   primary key (Borrow_card_id, Book_id)
);

/*==============================================================*/
/* Table: Borrower                                              */
/*==============================================================*/
create table Borrower
(
   Borrow_card_id       varchar(10) not null,
   Name                 varchar(20) not null,
   Company              varchar(20),
   primary key (Borrow_card_id)
);

/*==============================================================*/
/* Table: Libary                                                */
/*==============================================================*/
create table Libary
(
   Book_id              varchar(20) not null,
   Press_name           varchar(20),
   Book_name            varchar(20) not null,
   Varieties            varchar(20),
   Storage_location     varchar(20),
   Borrow_data          date,
   Return_data          date,
   primary key (Book_id)
);

/*==============================================================*/
/* Table: Press_information                                     */
/*==============================================================*/
create table Press_information
(
   Press_name           varchar(20) not null,
   Press_E_mail         varchar(20) not null,
   Call_number          varchar(20) not null,
   Zip_code             varchar(10),
   Address              varchar(30),
   primary key (Press_name)
);

alter table Borrow add constraint FK_Borrow foreign key (Borrow_card_id)
      references Borrower (Borrow_card_id) on delete restrict on update restrict;

alter table Borrow add constraint FK_Borrow2 foreign key (Book_id)
      references Libary (Book_id) on delete restrict on update restrict;

alter table Libary add constraint FK_Issue foreign key (Press_name)
      references Press_information (Press_name) on delete restrict on update restrict;

分析思考问题:

  1. 试分析概念模型和物理模型的区别;

    概念模型:概念模型是对真实世界中问题域内的事物的描述,不是对软件设计的描述。常用"实体-关系"(E-R)图表示概念模型。E-R图主要是由实体、属性和关系三个要素构成的。

    物理模型:物理模型是对真实数据库的描述。数据库中的一些对象如下:表,视图,字段,数据类型、长度、主键、外键、索引、是否可为空,默认值。

    概念模型到物理模型的转换即是把概念模型中的对象转换成物理模型的对象。

  2. 试分析概念模型与物理模型转换时的映射关系是如何的。

    包含多种关系的映射

    Relationship:关系,包括 one to one,one to many 和many to many这三种联系类型,以及另外三个可以设置的属性:mandatory(强制性联系), dependent(依赖性联系/标定关联) 和dominant(统制联系)。

    Association:关联,在很多情况下(特别是多对多关系中),我们会把联系专门提出来,作为一个实体型放在两个需要被关联的实体型中间(在PD中,选中任何一个联系,在右键的弹出菜单中选择“Change to Entity”命令即可完成联系转实体的操作)。但有的时候,把若干个实体型之间的联系抽象为一个实体型可能不太合适,这个时候你可以选择为这些实体型建立一个association,那么在生成PDM的时候,所有这些相关实体型的identifier都会被加入到association对应生成的表模型中。所以,说白了,其实association就是实体型的一种特例,用来在建模的时候更确切的表达实体间的关联信息。在PD的文档中举了一个录音带、顾客、商店三个实体型在租借录音带这个场景上发生关联,然后把租借定义为上述三个实体型之间的association的例子,非常确切。在我们的学校模型里,我定义了家访做为老师和学生实体型中间的一个association,在接下来产生的PDM中大家就可能看到这种定义所产生的效果。

五、讨论、心得

在学习PowerDesigner过程中充分了解了具体数据库实现相关的数据建模,而作为数据库的开发设计人员,必须能熟练应用此数据建模工具,以帮助自己减少错误。

你可能感兴趣的:(#,ZUCC数据库原理,数据库,database)