多房间预订的数据库设计:一对多
主要实体: 客户 客人 预订 RoomAssignment
我想实现一个多房间预订数据库设计。首先,我想先解释一下这个概念:
- 客户是获得预订的人。
- 客户一次只能预订 1 个房间
- 客户可以预订多个房间。
客人是被分配到特定房间的人。
对于表格来说:
客户端(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:
- The Client is the one who acquires a reservation.
- The Client can only have 1 reservation at a time
- The Client can reserve multiple rooms.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(编辑经过更多思考后更改了我的建议。这是一个比我最初想象的更深的谜题。)
我的偏好是让保留具有多对多关系(使用桥接表)有房间。使用 ReservationID 和 RoomID 外键调用此表,例如 . 。 。 预订。也许你可以想出一个更好的名字。预订是预订的特定房间。然后,我会有另一个桥接表来表示“客人”和“预订”之间的关系。您可以将其称为住宿。住宿是指被分配到特定预订(预订的房间)的特定客人。
这是一个巧妙的谜题。关键是你有几个单独存在并且显然是必要的具体事物(预订、房间、客人),但也有几个其他概念,每个概念都有自己的属性,并且源于这些事物之间的关系。如果要正确标准化,您最终可能会得到比您想象的更多的表。不要认为这会变得更加复杂。拥有足够的适当表格将最终简化这一过程。以下是一些其他建议:
(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: