[英]How would I go about designing this database?
I'm working on a shared booking system, tables would be a User table for each individual user and a Bookings table for the bookings.我在共享预订系统上工作,表格将是每个用户的用户表和预订的预订表。
A user can have multiple bookings and a booking can only have up to 8 users in each individual booking.一个用户可以有多个预订,每个预订最多只能有 8 个用户。
In each individual booking I need to store each user's id and their number of suitcases What would be an easy and efficient way to design this?在每个单独的预订中,我需要存储每个用户的 ID 和他们的手提箱数量。设计这个的简单有效的方法是什么? Seeing as in a booking there could be 8 different user foreign keys and 8 different number of suitcases related to their own user?
看到在预订中可能有 8 个不同的用户外键和 8 个不同数量的与他们自己的用户相关的手提箱?
Any pointers would be appreciated.任何指针将不胜感激。
That 8 users per booking limitation is a limitation of your system, not of any database.每个预订限制 8 个用户是您系统的限制,而不是任何数据库的限制。 And it's an arbitrary one at that, but seeing the fields you're using it looks like homework more than anything actually useful, so that's a given I suppose.
这是一个任意的,但看到你正在使用的字段看起来更像是家庭作业,而不是任何实际有用的东西,所以我想这是给定的。 My point is that you can ignore that limitation when designing your database.
我的观点是,您可以在设计数据库时忽略该限制。
So with that in mind, what you have are three tables:因此,考虑到这一点,您拥有的是三个表:
User
( id
PK, name
, address
) User
( id
PK, name
, address
)Booking
( id
PK, suitcases
) Booking
( id
PK, suitcases
)UserBooking
( id
PK, user_id
FK( User
), booking_id
FK( Booking
)) UserBooking
( id
PK, user_id
FK( User
), booking_id
FK( Booking
)) As to the 8 users per booking limit, either use triggers to reject inserts in UserBooking
if the condition fails, or use a stored procedure and transactions to check before inserting.对于每个预订的 8 个用户限制,如果条件失败,则使用触发器拒绝在
UserBooking
中插入,或者使用存储过程和事务在插入前进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.