酒店管理系统实体关系图反馈

问题描述 投票:0回答:1

Stack Overflow 社区您好,

我为酒店管理系统创建了实体关系图 (ERD)。这是我创建的 ERD:

See the ERD Diagram here:

您也可以在此处访问图表:

https://lucid.app/lucidchart/9de3840f-fa55-4f2c-ad8e-1894f34c0923/edit?viewport_loc=830%2C-268%2C3328%2C1630%2C0_0&invitationId=inv_7394002a-3755-4e37-a831-9 c713f222344

我将表格分为以下几组:

位置信息:国家、城市 酒店信息:酒店、类别、房间、ROOM_TYPE 用户信息:客人、员工、角色 交易信息:预订、预订房间、发票、评论 对于以下方面的任何反馈或建议,我将不胜感激:

表之间的关系是否正确表示? 是否有任何不必要或缺失的表或关系? 表格的类别是否合适? 这是我用来创建 ERD 的 SQL 架构:

BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE COUNTRIES (
        id NUMBER PRIMARY KEY,
        country_name VARCHAR2(255) NOT NULL
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE CITIES (
        id NUMBER(4) PRIMARY KEY,
        city_name VARCHAR2(100) NOT NULL,
        postal_code VARCHAR2(10),
        country_id NUMBER(4),
        FOREIGN KEY (country_id) REFERENCES COUNTRIES(id)
    )'; 

    EXECUTE IMMEDIATE 'CREATE TABLE CATEGORIES (
        id NUMBER(4) PRIMARY KEY,
        category_name VARCHAR2(255) NOT NULL
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE GUESTS (
        id NUMBER(10) PRIMARY KEY,
        first_name VARCHAR2(255) NOT NULL,
        last_name VARCHAR2(255) NOT NULL,
        email VARCHAR2(255),
        phone VARCHAR2(15) NOT NULL,
        address VARCHAR2(255),
        details CLOB
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE HOTELS (
        id NUMBER(4) PRIMARY KEY,
        hotel_name VARCHAR2(100) NOT NULL,
        description CLOB,
        phone_number VARCHAR2(10),
        email VARCHAR2(100) NOT NULL,
        category_id NUMBER(4) NOT NULL,
        city_id NUMBER(4) NOT NULL,
        FOREIGN KEY (category_id) REFERENCES CATEGORIES(id),
        FOREIGN KEY (city_id) REFERENCES CITIES(id)
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE REVIEWS (
        id NUMBER(4) PRIMARY KEY,
        message CLOB NOT NULL,
        review_date DATE NOT NULL,
        guest_id NUMBER(4),
        FOREIGN KEY (guest_id) REFERENCES GUESTS(id),
        hotel_id NUMBER(4),
        FOREIGN KEY (hotel_id) REFERENCES HOTELS(id)
    )';

   

    EXECUTE IMMEDIATE 'CREATE TABLE ROOM_TYPE (
        id NUMBER(4) PRIMARY KEY,
        type_name VARCHAR2(255) NOT NULL,
        type_description VARCHAR2(255)
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE ROOMS (
        id NUMBER(4) PRIMARY KEY,
        room_name VARCHAR2(255) NOT NULL,
        hotel_id NUMBER(4),
        FOREIGN KEY (hotel_id) REFERENCES HOTELS(id),
        description CLOB,
        room_price NUMBER(10, 2) NOT NULL,
        room_type_id NUMBER(4),
        FOREIGN KEY (room_type_id) REFERENCES ROOM_TYPE(id),
        additional_features CLOB
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE RESERVATIONS (
        id NUMBER(10) PRIMARY KEY,
        guest_id NUMBER(10),
        FOREIGN KEY (guest_id) REFERENCES GUESTS(id),
        checkin_date DATE NOT NULL,
        checkout_date DATE NOT NULL,
        creation_time TIMESTAMP NOT NULL,
        discount_percent NUMBER(5, 2),
        total_price NUMBER(10, 2) NOT NULL
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE ROOM_RESERVED (
        id NUMBER(10) PRIMARY KEY,
        reservation_id NUMBER(10),
        room_id NUMBER(4),
        FOREIGN KEY (reservation_id) REFERENCES RESERVATIONS(id),
        FOREIGN KEY (room_id) REFERENCES ROOMS(id)
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE INVOICES (
        id NUMBER(10) PRIMARY KEY,
        guest_id NUMBER(10),
        reservation_id NUMBER(10),
        FOREIGN KEY (guest_id) REFERENCES GUESTS(id),
        FOREIGN KEY (reservation_id) REFERENCES RESERVATIONS(id),
        invoice_amount NUMBER(10, 2) NOT NULL,
        invoice_date DATE NOT NULL,
        payment_date DATE,
        due_date DATE NOT NULL
    )';
    EXECUTE IMMEDIATE 'CREATE TABLE ROLES (
        id NUMBER(10) PRIMARY KEY,
        role_name VARCHAR2(255) NOT NULL
    )';

    EXECUTE IMMEDIATE 'CREATE TABLE EMPLOYEES (
        id NUMBER(10) PRIMARY KEY,
        first_name VARCHAR2(255) NOT NULL,
        last_name VARCHAR2(255) NOT NULL,
        email VARCHAR2(255),
        role_id NUMBER(10),
        salary NUMBER(10, 2) NOT NULL,
        reports_to NUMBER(10) REFERENCES EMPLOYEES(id),
        FOREIGN KEY (role_id) REFERENCES ROLES(id),
        hotel_id NUMBER,
        FOREIGN KEY (hotel_id) REFERENCES HOTELS(id)
    )';


EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);
END;
/




建议,以及可能的最终版本。

sql oracle database-design erd
1个回答
0
投票

您的图表在很大程度上是有意义的,并且通常是正确的,假设实体和列的名称是不言自明的并且意味着大多数人所理解的含义。

我确实看到的一个错误是

invoices
实体 - 你让它参与了两个一对一的关系,同时具有
guest
reservation
。到
guest
的链接几乎肯定是错误的,因为它创建了两条通往
guest
的路径。这导致了两个可能的事实,而这正是我们通过正常化试图避免的。只要有
reservation
的链接就足够了 - 您可以通过这种方式联系到客人。另外,这真的应该是一对一的吗?如果您只能为一项预订开具一张发票,也许您应该将这两个实体合二为一。如果您可以为同一预订开具多张发票,请将关系更新为一对多。

© www.soinside.com 2019 - 2024. All rights reserved.