《数据库系统》课程实践任务报告任务名称: 某宾馆客房管理系统班级:学号:姓名:学号:姓名:完成日期: 2015年06月30日信息工程学院计算机系任务名称:某宾馆客房管理系统1.任务的描述随着宾馆业竞争的加剧,传统的宾馆计算机管理系统已无法满足宾馆信息化管理的需要。
为了拓展经营空间、降低成本和提高管理效率,宾馆需要使用更高效的信息化手段,借助先进的计算机信息技术对宾馆进行管理。
因此为了对某宾馆实现客房情况的信息化管理,特设计并实现一个涉及到SQL Server数据库的重要数据库对象、功能和特性的某宾馆客房管理系统,新的宾馆客房管理系统科学的将宾馆各种业务完美的结合,方便管理和决策,并且能提供大量的管理经营过程中实际的数据。
宾馆客房管理系统要求实现以下功能:1、实现客房类型、价目信息、客房信息的管理;2、实现客户信息的管理;3、实现入住和退房管理;4、实现费用管理;5、创建触发器,实现入住和退房时自动修改客房的状态;6、创建存储过程统计某段时间内各种类型的客房的入住时间合计和费用合计;7、创建视图查询某一时刻没有入住的房间信息;8、建立数据库相关表之间的参照完整性约束。
2.需求分析本系统主要包括的外部实体有:客户、客房信息、客户住宿、前台、客房状态,要实现的功能主要有:客户、客房等信息的管理。
2.1 系统包含的实体根据“任务描述”中提供的信息以及系统需要实现的功能,本系统应包含的实体及其包含的属性名如下:客户(身份证号码,姓名,性别,出生日期,地址)前台(编号,姓名)客房信息(客房号,客房类型,客房数量,价格,客房状态)客户住宿(客房号,客房类型,入住时间,消费费用,住宿时间,退房时间)费用(客房类型,房费,消费费用,押金)入住信息(入住编号,入住时间,入住人数)退房信息(退房编号,退房时间)客房类型(类型编号,类型名称,价格)楼层信息(楼层编号,楼层名)2.2 系统包含的实体间联系根据“任务描述”中提供的信息以及宾馆的实际情况,本系统中实体之间应有如下的联系:存在联系:实体“客户”与“客房”之间的联系,包含属性:客房号。
联系类型:一对多。
入住联系:实体“客户”与“入住信息”之间的联系,不包含属性。
联系类型:一对多。
住宿联系:实体“客房”与“客户住宿”之间的联系,包含属性:客房号,客房类型。
联系类型:一对多。
包含联系:实体“客房”与“客房类型”之间的联系,不包含属性。
联系类型:一对多。
属于联系:实体“客房”与“楼层信息”之间的联系,不包含属性。
联系类型:多对多。
管理联系:实体“客户”与“前台”之间的联系,不包含属性。
联系类型:一对多。
2.3系统需实现的功能根据“任务描述”中提供的信息以及宾馆的实际情况,本系统需具有如下的功能:1、对本系统中具有的实体及实体间联系的信息存储;2、具体有如下的静态查询:1)对客房信息(客房号、收费标准、类型、入住情况)的查询:2)对客户信息(身份证号、居住地址、姓名、性别、出生日期等)的查询;3)对客户住宿信息(客房号,客房类型,入住时间,住宿费用,住宿时间,退房时间)的查询;4)对客房状态(入住、退房)的查询;3、具体有如下的动态查询:1)给定身份证号码,查询该客户的身份信息、客户住宿信息;2)给定客房号,查询该客房的信息、客房状态;2.4 数据流图根据“需要分析”中对本系统包含的实体及需要实现的功能的描述,设计并绘制出本系统的数据流图如下:(1)第一层数据流图(2)第二层数据流图2.5 数据字典根据数据流图中的实体、数据存储,本系统需要如下数据字典:(1)数据字典名:客户表示的对象:客户实体数据结构:客户=姓名(字符串类型)+性别(字符串类型)+地址(字符串类型)+出生日期(日期类型)+身份证号(字符串类型)+电话(字符串类型)(2)数据字典名:前台表示的对象:前台实体数据结构:前台=姓名(字符串类型)+性别(字符串类型)(3)数据字典名:客房表示的对象:客房实体数据结构:客房=客房号(整型)+客房类型(字符串类型)+客房数量(整型)+价格(整型)+客房状态(字符串类型)(4)数据字典名:客户住宿表示的对象:客户住宿实体数据结构:客户住宿=客房号(整型)+客房类型(字符串类型)+住宿时间(字符串类型)+消费费用(整型)+入住时间(字符串类型)+退房时间(字符串类型)(5)数据字典名:客房类型表示的对象:客房类型实体数据结构:客房类型=类型编号(字符串类型)+类型名称(整型)(6)数据字典名:账单信息表示的对象:账单信息实体数据结构:账单信息=客房类型(字符串类型)+消费费用(整型)+房费(整型)+押金(整型)(7)数据字典名:入住信息表示的对象:入住信息实体数据结构:入住信息=入住编号(定长字符串类型)+入住人数(整型)+ 入住时间(字符串类型)(8)数据字典名:退房信息表示的对象:退房信息实体数据结构:退房信息=退房编号(定长字符串类型)+ 退房时间(字符串类型)(9)数据字典名:楼层信息表示的对象:楼层信息实体数据结构:楼层信息=楼层编号(定长字符串类型)+ 楼层名(字符串类型)3. 数据库概念数据模型设计根据“需求分析”中对本系统包含的实体及实体间联系的描述,本系统的数据库概念数据模型图如下:4.数据库逻辑数据模型设计此处根据数据库概念数据模型和数据库概念模型向关系数据库模型转换的规则,生成出系统的数据库逻辑数据模型。
5. 数据库物理数据模型设计此处根据数据库概念数据模型生成数据库物理数据模型后,截图粘贴到此处。
6.建立数据库的SQL代码if exists(select 1 from sys.sysforeignkey where role='FK_ENTITY_6_RELATIONS_客户') thenalter table Entity_6delete foreign key FK_ENTITY_6_RELATIONS_客户end if;if exists(select 1 from sys.sysforeignkey where role='FK_客户_RELATIONS_客房') then alter table 客户delete foreign key FK_客户_RELATIONS_客房end if;if exists(select 1 from sys.sysforeignkey where role='FK_客户_RELATIONS_ENTITY_8')thenalter table 客户delete foreign key FK_客户_RELATIONS_ENTITY_8end if;if exists(select 1 from sys.sysforeignkey where role='FK_客户_RELATIONS_ENTITY_9') thenalter table 客户delete foreign key FK_客户_RELATIONS_ENTITY_9end if;if exists(select 1 from sys.sysforeignkey where role='FK_客户住宿_RELATIONS_客房') thenalter table 客户住宿delete foreign key FK_客户住宿_RELATIONS_客房end if;if exists(select 1 from sys.sysforeignkey where role='FK_客房_RELATIONS_前台') then alter table 客房delete foreign key FK_客房_RELATIONS_前台end if;if exists(select 1 from sys.sysforeignkey where role='FK_客房_RELATIONS_ENTITY_7') thenalter table 客房delete foreign key FK_客房_RELATIONS_ENTITY_7end if;if exists(select 1 from sys.sysforeignkey where role='FK_客房_RELATIONS_ENTITY_1') thenalter table 客房delete foreign key FK_客房_RELATIONS_ENTITY_1 end if;drop index if exists Entity_10.Entity_10_PK;drop table if exists Entity_10;drop index if exists Entity_6.Relationship_7_FK;drop index if exists Entity_6.Entity_6_PK;drop table if exists Entity_6;drop index if exists Entity_7.Entity_7_PK;drop table if exists Entity_7;drop index if exists Entity_8.Entity_8_PK;drop table if exists Entity_8;drop index if exists Entity_9.Entity_9_PK;drop table if exists Entity_9;drop index if exists 前台.前台_PK;drop table if exists 前台;drop index if exists 客户.Relationship_5_FK;drop index if exists 客户.Relationship_4_FK;drop index if exists 客户.Relationship_3_FK;drop index if exists 客户.客户_PK;drop table if exists 客户;drop index if exists 客户住宿.Relationship_6_FK;drop index if exists 客户住宿.客户住宿_PK;drop table if exists 客户住宿;drop index if exists 客房.Relationship_8_FK;drop index if exists 客房.Relationship_2_FK;drop index if exists 客房.Relationship_1_FK;drop index if exists 客房.客房_PK;drop table if exists 客房;/*==============================================================*/ /* Table: Entity_10 */ /*==============================================================*/ create table Entity_10(Attribute_34 char(10) not null, Attribute_35 char(10) null,constraint PK_ENTITY_10 primary key (Attribute_34));/*==============================================================*/ /* Index: Entity_10_PK */ /*==============================================================*/ create unique index Entity_10_PK on Entity_10 (Attribute_34 ASC);/*==============================================================*/ /* Table: Entity_6 */ /*==============================================================*/ create table Entity_6(Attribute_21 char(10) not null, 身份证号 char(18) null, Attribute_22 char(10) null,Attribute_23 char(10) null,Attribute_24 char(10) null,constraint PK_ENTITY_6 primary key (Attribute_21));/*==============================================================*/ /* Index: Entity_6_PK */ /*==============================================================*/ create unique index Entity_6_PK on Entity_6 (Attribute_21 ASC);/*==============================================================*//* Index: Relationship_7_FK */ /*==============================================================*/ create index Relationship_7_FK on Entity_6 (身份证号 ASC);/*==============================================================*/ /* Table: Entity_7 */ /*==============================================================*/ create table Entity_7(Attribute_26 char(10) not null, Attribute_27 char(10) null,Attribute_28 char(10) null,constraint PK_ENTITY_7 primary key (Attribute_26));/*==============================================================*/ /* Index: Entity_7_PK */ /*==============================================================*/ create unique index Entity_7_PK on Entity_7 (Attribute_26 ASC);/*==============================================================*/ /* Table: Entity_8 */ /*==============================================================*/ create table Entity_8(Attribute_29 char(10) not null, Attribute_30 char(10) null,Attribute_31 char(10) null,constraint PK_ENTITY_8 primary key (Attribute_29));/*==============================================================*/ /* Index: Entity_8_PK */ /*==============================================================*/ create unique index Entity_8_PK on Entity_8 (Attribute_29 ASC);/*==============================================================*/ /* Table: Entity_9 */ /*==============================================================*/ create table Entity_9(Attribute_32 char(10) not null,Attribute_33 char(10) null,constraint PK_ENTITY_9 primary key (Attribute_32));/*==============================================================*/ /* Index: Entity_9_PK */ /*==============================================================*/ create unique index Entity_9_PK on Entity_9 (Attribute_32 ASC);/*==============================================================*/ /* Table: 前台 */ /*==============================================================*/create table 前台(编号 char(10) not null, 姓名 varchar(20) null,constraint PK_前台 primary key (编号));/*==============================================================*/ /* Index: 前台_PK */ /*==============================================================*/ create unique index 前台_PK on 前台 (编号 ASC);/*==============================================================*/ /* Table: 客户 */ /*==============================================================*/ create table 客户(身份证号 char(18) not null, Attribute_32 char(10) null, 客房号 char(10) null,Attribute_29 char(10) null, 姓名 varchar(20) null,性别 char(2) null,地址 long varchar null,出生日期 timestamp null,电话 char(11) null,constraint PK_客户 primary key (身份证号));/*==============================================================*//* Index: 客户_PK */ /*==============================================================*/ create unique index 客户_PK on 客户 (身份证号 ASC);/*==============================================================*//* Index: Relationship_3_FK *//*==============================================================*/ create index Relationship_3_FK on 客户 (客房号 ASC);/*==============================================================*//* Index: Relationship_4_FK *//*==============================================================*/ create index Relationship_4_FK on 客户 (Attribute_29 ASC);/*==============================================================*//* Index: Relationship_5_FK *//*==============================================================*/ create index Relationship_5_FK on 客户 (Attribute_32 ASC);/*==============================================================*//* Table: 客户住宿 */ /*==============================================================*/create table 客户住宿(Attribute_17 char(10) not null,Attribute_18 char(10) not null, 客房号 char(10) null,入住时间 char(10) null,住宿时间 char(10) null,退房时间 char(10) null,消费费用 char(10) null,constraint PK_客户住宿 primary key (Attribute_17, Attribute_18) );/*==============================================================*//* Index: 客户住宿_PK */ /*==============================================================*/ create unique index 客户住宿_PK on 客户住宿 (Attribute_17 ASC,Attribute_18 ASC);/*==============================================================*//* Index: Relationship_6_FK *//*==============================================================*/ create index Relationship_6_FK on 客户住宿 (客房号 ASC);/*==============================================================*//* Table: 客房 */ /*==============================================================*/ create table 客房客房号 char(10) not null, Attribute_26 char(10) null, 编号 char(10) null,Attribute_34 char(10) not null, 客房类型 char(10) null,客房状态 char(10) null,价格 char(10) null,constraint PK_客房 primary key (客房号));/*==============================================================*/ /* Index: 客房_PK */ /*==============================================================*/ create unique index 客房_PK on 客房 (客房号 ASC);/*==============================================================*/ /* Index: Relationship_1_FK */ /*==============================================================*/ create index Relationship_1_FK on 客房 (编号 ASC);/*==============================================================*/ /* Index: Relationship_2_FK */ /*==============================================================*/ create index Relationship_2_FK on 客房 (Attribute_26 ASC);/*==============================================================*//* Index: Relationship_8_FK *//*==============================================================*/ create index Relationship_8_FK on 客房 (Attribute_34 ASC);alter table Entity_6add constraint FK_ENTITY_6_RELATIONS_客户 foreign key (身份证号)references 客户 (身份证号)on update restricton delete restrict;alter table 客户add constraint FK_客户_RELATIONS_客房 foreign key (客房号)references 客房 (客房号)on update restricton delete restrict;alter table 客户add constraint FK_客户_RELATIONS_ENTITY_8 foreign key (Attribute_29) references Entity_8 (Attribute_29)on update restricton delete restrict;alter table 客户add constraint FK_客户_RELATIONS_ENTITY_9 foreign key (Attribute_32) references Entity_9 (Attribute_32)on update restricton delete restrict;alter table 客户住宿add constraint FK_客户住宿_RELATIONS_客房 foreign key (客房号)references 客房 (客房号)on update restricton delete restrict;alter table 客房add constraint FK_客房_RELATIONS_前台 foreign key (编号)references 前台 (编号)on update restricton delete restrict;alter table 客房add constraint FK_客房_RELATIONS_ENTITY_7 foreign key (Attribute_26) references Entity_7 (Attribute_26)on update restricton delete restrict;alter table 客房add constraint FK_客房_RELATIONS_ENTITY_1 foreign key (Attribute_34) references Entity_10 (Attribute_34)on update restricton delete restrict;。