多房间预订的数据库设计:一对多

发布于 2025-01-05 08:50:03 字数 1050 浏览 1 评论 0原文

主要实体: 客户 客人 预订 RoomAssignment

我想实现一个多房间预订数据库设计。首先,我想先解释一下这个概念:

  1. 客户是获得预订的人。
  2. 客户一次只能预订 1 个房间
  3. 客户可以预订多个房间。
  4. 客人是被分配到特定房间的人。

    对于表格来说:

    客户端(client_id(PK)、名称)
    访客(guest_id(PK),姓名)

    预订 (reservation_id(PK), client_id(FK), roomAss_id(FK), checkInDate);
    RoomAssignment (roomAss_id(PK), guest_id(FK), roomno(FK));
    房间(room_id(PK),房间详细信息);
    

//这里的问题是我不知道如何实现一对多的关系。我的预订应该处理多个房间分配吗?或者我的 RoomAssignment 将处理多个 guest_id 和 roomno,然后我将 1 个 roomass_id 传递到我的预订表中?

谢谢,我对这种一对多的关系真的很困惑。我希望有人能好心地帮助我,而不是给我负面的分数。 T_T

另一种尝试:(

Room(room_id(PK), roomDetails);
Client (client_id(PK), Name)
Guest (guest_id(PK), Name)
Reservation (reservation_id(PK), client_id(FK), checkInDate);
Booking(book_id(PK), reservation_id(FK), room_id(FK));
Lodging(lodge_id(PK), guest_id(FK), book_id(FK))

客户、房间、客人已填满),添加预订、添加预订、添加住宿

这是正确的吗?

Primary Entities:
Client
Guest
Reservation
RoomAssignment

I want to implement a multiple room reservation database design. First, I want to explain first the concept:

  1. The Client is the one who acquires a reservation.
  2. The Client can only have 1 reservation at a time
  3. The Client can reserve multiple rooms.
  4. The Guest is the one who is assigned into a specific room.

    So for the Table:

    Client (client_id(PK), Name)
    Guest (guest_id(PK), Name)

    Reservation (reservation_id(PK), client_id(FK), roomAss_id(FK), checkInDate);
    RoomAssignment (roomAss_id(PK), guest_id(FK), roomno(FK));
    Room(room_id(PK), roomDetails);
    

//The problem here is that I don't know how to implement a 1 to many relationship. My Reservation should handle mutliple RoomAssignment? Or my RoomAssignment will handle multiple guest_id and roomno and then I will pass 1 roomass_id into my reservation table?

Thanks I am really confused about this 1 to many relationship. I hope somebody is so kind to help instead of giving me negative points. T_T

Another Attempt:

Room(room_id(PK), roomDetails);
Client (client_id(PK), Name)
Guest (guest_id(PK), Name)
Reservation (reservation_id(PK), client_id(FK), checkInDate);
Booking(book_id(PK), reservation_id(FK), room_id(FK));
Lodging(lodge_id(PK), guest_id(FK), book_id(FK))

(Client, Room, Guest are already filled), add Reservation, add Booking, add Lodging

Is This Correct??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼睛不忧郁 2025-01-12 08:50:04

编辑经过更多思考后更改了我的建议。这是一个比我最初想象的更深的谜题。)

我的偏好是让保留具有多对多关系(使用桥接表)有房间。使用 ReservationID 和 RoomID 外键调用此表,例如 . 。 。 预订。也许你可以想出一个更好的名字。预订是预订的特定房间。然后,我会有另一个桥接表来表示“客人”和“预订”之间的关系。您可以将其称为住宿。住宿是指被分配到特定预订(预订的房间)的特定客人。

这是一个巧妙的谜题。关键是你有几个单独存在并且显然是必要的具体事物(预订、房间、客人),但也有几个其他概念,每个概念都有自己的属性,并且源于这些事物之间的关系。如果要正确标准化,您最终可能会得到比您想象的更多的表。不要认为这会变得更加复杂。拥有足够的适当表格将最终简化这一过程。以下是一些其他建议:

  • 花时间研究每个表的名称。我上面的建议非常好,但您可能可以改进它们。预订既是其他事物之间的关系,又成为一种思考本身,在另一张桌子上至少有一个外键。
  • 您应该能够描述表中的记录代表什么。如果你做不到这一点,那么你的桌子就很糟糕。请参阅上面我如何描述什么是预订和住宿。您的设计最终可能会有所不同,但是当您对不同的表进行集体讨论时,请确保您可以描述该表上的记录实际上是什么。
  • 考虑让客人和客户来自同一张桌子。他们俩确实是“联系人”。有人可能在某一时刻是客人,但在下个月就成为客户。当联系人是客户时,您可能会保留一个额外的数据表(1 到 0 或 1)。如果某人只是充当访客,您的系统只需要基本的联系信息,但如果他们充当客户,则需要更多信息。

(Edit Changed my suggestion after thinking about this more. It's a deeper puzzle than I first thought.)

My preference would be to have the Reservation having a many-to-many relationship (using a bridge table) with rooms. Call this table, with ReservationID and RoomID foreign keys, something like . . . Booking. Maybe you can think of a better name. A Booking is a particular room being reserved. Then, I'd have another bridge table representing the relationship between a Guest and a Booking. You could maybe call that a Lodging. A Lodging is a particular guest being assigned to a particular Booking (a booked room).

This is a neat puzzle you have. The key is that you have several concrete things that exist on their own and are obviously necessary (reservation, room, guest), but also several other concepts, each with their own attributes, and spring from the relationship between these things. If this is going to be normalized correctly, you might end up with more tables than you guessed. Don't think of this as getting more complicated. Having the enough of the proper tables is what's going to ultimately simplify this. Here are some other suggestions:

  • Spend time on the names of each table. My suggestions above are pretty good, but you can probably improve them. A booking is both a relationship between other things, but becomes a think itself, with at least one foreign key on another table.
  • You should be able to describe what a record on a table represents. If you can't do that, then your tables suck. See above how I can describe what a booking and lodging are. Your design might end up being different, but as you brainstorm different tables, make sure you can describe what a record on that table actually is.
  • Consider having Guest and Client being from the same table. They're both "Contacts" really. Someone might be a Guest at one point, but a Client the next month. You might ave an extra data table (one to 0-or-1) for when a Contact is the Client. You're system would only demand basic Contact information if someone is going to just act as a Guest, but more if they're acting as a Client.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文