系统设计与分析Homework5

a. 阅读 Asg_RH 文档,按用例构建领域模型。

Lingyu

b. 数据库建模(E-R模型)

  • 按 Task 3 要求,给出系统的 E-R 模型(数据逻辑模型)
  • 导出 Mysql 物理数据库的脚本
  • 简单叙说 数据库逻辑模型 与 领域模型 的异同
    ER
    导出脚本:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    drop table if exists Credit_card;

    drop table if exists Hotel;

    drop table if exists Location;

    drop table if exists Reservation;

    drop table if exists Room;

    drop table if exists Traveler;

    /*==============================================================*/
    /* Table: Credit_card */
    /*==============================================================*/
    create table Credit_card
    (
    card_id int not null,
    card_number int null,
    security_code int null,
    constraint PK_CREDIT_CARD primary key clustered (card_id)
    );

    /*==============================================================*/
    /* Table: Hotel */
    /*==============================================================*/
    create table Hotel
    (
    hotel_id int not null,
    location_id int null,
    name long varchar null,
    address long varchar null,
    "star rat" int null,
    constraint PK_HOTEL primary key clustered (hotel_id)
    );

    /*==============================================================*/
    /* Table: Location */
    /*==============================================================*/
    create table Location
    (
    location_id int not null,
    name long varchar null,
    hot int null,
    constraint PK_LOCATION primary key clustered (location_id)
    );

    /*==============================================================*/
    /* Table: Reservation */
    /*==============================================================*/
    create table Reservation
    (
    reservation_id int not null,
    hotel_id int null,
    room_id int null,
    traveler_id int null,
    card_id int null,
    check_in_date date null,
    check_out_date date null,
    constraint PK_RESERVATION primary key clustered (reservation_id)
    );

    /*==============================================================*/
    /* Table: Room */
    /*==============================================================*/
    create table Room
    (
    room_id int not null,
    hotel_id int null,
    price double null,
    availability char null,
    type long varchar null,
    constraint PK_ROOM primary key clustered (room_id)
    );

    /*==============================================================*/
    /* Table: Traveler */
    /*==============================================================*/
    create table Traveler
    (
    name long varchar null,
    address long varchar null,
    "phone number" int null,
    email long varchar null,
    traveler_id int not null,
    constraint PK_TRAVELER primary key clustered (traveler_id)
    );

    alter table Hotel
    add constraint FK_HOTEL_REFERENCE_LOCATION foreign key (location_id)
    references Location (location_id)
    on update restrict
    on delete restrict;

    alter table Reservation
    add constraint FK_RESERVAT_REFERENCE_HOTEL foreign key (hotel_id)
    references Hotel (hotel_id)
    on update restrict
    on delete restrict;

    alter table Reservation
    add constraint FK_RESERVAT_REFERENCE_ROOM foreign key (room_id)
    references Room (room_id)
    on update restrict
    on delete restrict;

    alter table Reservation
    add constraint FK_RESERVAT_REFERENCE_TRAVELER foreign key (traveler_id)
    references Traveler (traveler_id)
    on update restrict
    on delete restrict;

    alter table Reservation
    add constraint FK_RESERVAT_REFERENCE_CREDIT_C foreign key (card_id)
    references Credit_card (card_id)
    on update restrict
    on delete restrict;

    alter table Room
    add constraint FK_ROOM_REFERENCE_HOTEL foreign key (hotel_id)
    references Hotel (hotel_id)
    on update restrict
    on delete restrict;

简单叙说 数据库逻辑模型 与 领域模型 的异同

  • 相同点:都对实际问题进行抽象,描述了实体和实体间的关系,更加直观的展示了彼此间的关系
  • 不同点:领域模型的重点在于将用例中的概念都一一列出,更加注重需求分析方面的联系,注重整个业务流程;而数据库逻辑模型是面向软件开发的模型,因此在数据库逻辑模型中,有属性的类型,主键,外键等,更加注重数据库结构的设计。