设计房屋租赁管理系统--PostgreSQL--数据库原理及应用

第一次 “数据库原理及应用”课程实践大作业

针对房屋租赁管理系统开发,设计该系统数据库,并在PostgreSQL数据库服务器中实现该数据库。

1)分析房屋租赁管理系统业务的基本数据需求,使用Power Designer建模工具,建立房屋租赁管理系统概念数据模型CDM。

2)针对关系数据库设计,在Power Designer建模工具中,将房屋租赁管理系统概念数据模型转换为系统逻辑数据模型LDM设计,并进行规范化完善设计。

3)针对PostgreSQL数据库实现,在Power Designer建模工具中,将房屋租赁管理系统逻辑数据模型转换为系统物理数据模型PDM设计。

4)在Power Designer建模工具中,将房屋租赁管理系统物理数据模型转换为SQL脚本程序

5)在PostgreSQL数据库服务器中,执行该SQL脚本程序,实现房屋租赁管理系统数据库对象创建实现

作业要求:在作业文档分别给出房屋租赁管理系统的概念数据模型、逻辑数据模型、物理数据模型模型设计图,

并将数据库设计模型在PostgreSQL数据库服务器进行实现。给出各个模型设计步骤、设计说明、执行结果界面,并对结果进行说明

实验流程

1.新建概念数据模型

 2.选取概念数据类型,输入名称

3.定义租户实体

 4.命名实体名称

 5.命名实体属性

6.同理定义房屋、房主、租贷合同实体

 

7.建立实体联系,点取实体联系符号,连接“租户”实体与“房屋”实体

 

8.双击联系符号,进入联系选项设置,命名实体联系名称

9.设置实体之间的数量关系、参与关系

10.类似方法建立其他实体之间的联系 

 

 

 

 11.保存概念数据模型

逻辑数据模型设计图

1.    在工具栏中选取创建逻辑数据模型菜单项

关于powerdesinger 出现Entity Attribute code uniqueness解决办法

Tool->check model...去掉Entity Attribute下Entity Attribute name uniqueness 和 Entity Attribute code uniqueness

关于powerdesinger 出现Entity Attribute code uniqueness解决办法_咸鱼恒星的博客-CSDN博客

2.    进入逻辑数据模型转换设置对话框,设置选项与名称后,点击确定

3.    即可将概念数据模型转换为逻辑数据模型

4.    对转换之后的逻辑数据模型进行完善设计,可以增加实体属性

5.    为了更完整展示逻辑数据模型显示内容,可选取工具菜单栏,显示选项菜单项;进入模型显示设置页面,对逻辑数据模型实体显示内容进行设置,点取确定,即可看到逻辑数据模型完整内容

 

物理数据模型设计图

1.    点取菜单工具Tools->创建物理数据模型Generate Physical Data Model

2.    选取DBMS :PostgreSQL 9.x, 命名物理数据模型名称,点击确定,即可将逻辑数据模型转换为物理数据模型

3.    对物理数据模型的显示内容进行设置, 可通过点取工具菜单中的显示选项菜单项, 进入模型显示设置页面, 对物理数据模型显示内容进行设置,即可看到所需要的模型设计内容

 转换为SQL脚本程序,并在PostgreSQL数据库服务器进行实现。

1.    点取数据库菜单栏"Databases"

2.    点取创建数据库菜单项Generate Database

3.    进入数据库设置对话框页面, 在对话框页面中设置脚本转换选项,即可转换为SQL脚本程序

 

4.    在文本编辑器中,可以打开创建的SQL文件,即可看到各个数据库对象创建的SQL语句

5.    执行SQL脚本创建数据库对象,在PostgreSQL数据库管理工具中,执行SQL脚本,实现数据库对象创建

6.    使用pgAdmin4数据库管理工具,连接PostgreSQL数据库服务器,在服务器中创建房屋租赁数据库HouseDB

7.    调入创建数据库对象的SQL脚本文件,Tool,Query Tool

 7.删除索引文件

 

8.运行 ,刷新数据库,完成

SQL文件内容

/*==============================================================*/
/* DBMS name:      PostgreSQL 9.x                               */
/* Created on:     2022Äê4ÔÂ24ÈÕ 19:57:04                          */
/*==============================================================*/

/*==============================================================*/
/* Table: contract                                              */
/*==============================================================*/
create table contract (
   IDnumber             VARCHAR(18)          not null,
   IDnumber2            VARCHAR(18)          not null,
   renttime2            DATE                 null,
   owner2               VARCHAR(20)          null,
   address2             VARCHAR(50)          null,
   tenement             VARCHAR(20)          null
);

/*==============================================================*/
/* Index: partyB_FK                                             */
/*==============================================================*/
create  index partyB_FK on contract (
IDnumber
);

/*==============================================================*/
/* Index: partyA_FK                                             */
/*==============================================================*/
create  index partyA_FK on contract (
IDnumber2
);

/*==============================================================*/
/* Table: house                                                 */
/*==============================================================*/
create table house (
   address              VARCHAR(50)          not null,
   area                 NUMERIC(5,2)         not null,
   owner                VARCHAR(20)          not null,
   housetype            CHAR(4)              not null,
   renttime             DATE                 null,
   rent                 VARCHAR(20)          null,
   number               SERIAL               not null,
   IDnumber             VARCHAR(18)          null,
   IDnumber2            VARCHAR(18)          not null,
   rentstate2           CHAR(4)              null,
   constraint PK_HOUSE primary key (number)
);

/*==============================================================*/
/* Index: house_PK                                              */
/*==============================================================*/
create unique index house_PK on house (
number
);

/*==============================================================*/
/* Index: rent_FK                                               */
/*==============================================================*/
create  index rent_FK on house (
IDnumber
);

/*==============================================================*/
/* Index: own_FK                                                */
/*==============================================================*/
create  index own_FK on house (
IDnumber2
);

/*==============================================================*/
/* Table: owner                                                 */
/*==============================================================*/
create table owner (
   name2                VARCHAR(20)          null,
   gender2              CHAR(2)              null,
   address3             VARCHAR(50)          not null,
   phonenumber2         VARCHAR(11)          null,
   identity             CHAR(4)              not null,
   IDnumber2            VARCHAR(18)          not null,
   constraint PK_OWNER primary key (IDnumber2)
);

/*==============================================================*/
/* Index: owner_PK                                              */
/*==============================================================*/
create unique index owner_PK on owner (
IDnumber2
);

/*==============================================================*/
/* Table: tenement                                              */
/*==============================================================*/
create table tenement (
   IDnumber             VARCHAR(18)          not null,
   name                 VARCHAR(20)          not null,
   gender               CHAR(2)              not null,
   phonenumber          VARCHAR(11)          not null,
   address              VARCHAR(50)          not null,
   renttime             DATE                 null,
   rentstate2           CHAR(4)              null,
   constraint PK_TENEMENT primary key (IDnumber)
);

/*==============================================================*/
/* Index: tenement_PK                                           */
/*==============================================================*/
create unique index tenement_PK on tenement (
IDnumber
);

alter table contract
   add constraint FK_CONTRACT_PARTYA_OWNER foreign key (IDnumber2)
      references owner (IDnumber2)
      on delete restrict on update restrict;

alter table contract
   add constraint FK_CONTRACT_PARTYB_TENEMENT foreign key (IDnumber)
      references tenement (IDnumber)
      on delete restrict on update restrict;

alter table house
   add constraint FK_HOUSE_OWN_OWNER foreign key (IDnumber2)
      references owner (IDnumber2)
      on delete restrict on update restrict;

alter table house
   add constraint FK_HOUSE_RENT_TENEMENT foreign key (IDnumber)
      references tenement (IDnumber)
      on delete restrict on update restrict;

猜你喜欢

转载自blog.csdn.net/aiqq136/article/details/124369179