课程名称 | 数据库系统概论实验 |
---|---|
实验项目名称 | 实验三 使用PowerDesigner设计物理模型并转换为数据库对象 |
物理模型(PDM):CDM反映了业务领域中信息之间的关系,它不依赖于物理实现。只有重要的业务信息才出现在CDM 中。PDM定义了模型的物理实现细节。例如,所选RDBMS的数据类型特征、索引定义、视图定义、存储过程定义、触发器定义等。
分析阶段的CDM转换成PDM后,便将抽象的实体、属性与关系,对应到实际数据库的数据表、字段、主键、外部索引键等内容。
PowerDesigner支持模型间的转换
使用PowerDesigner进行数据库设计的基本过程:
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;
试分析概念模型和物理模型的区别;
概念模型:概念模型是对真实世界中问题域内的事物的描述,不是对软件设计的描述。常用"实体-关系"(E-R)图表示概念模型。E-R图主要是由实体、属性和关系三个要素构成的。
物理模型:物理模型是对真实数据库的描述。数据库中的一些对象如下:表,视图,字段,数据类型、长度、主键、外键、索引、是否可为空,默认值。
概念模型到物理模型的转换即是把概念模型中的对象转换成物理模型的对象。
试分析概念模型与物理模型转换时的映射关系是如何的。
包含多种关系的映射
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过程中充分了解了具体数据库实现相关的数据建模,而作为数据库的开发设计人员,必须能熟练应用此数据建模工具,以帮助自己减少错误。