简体   繁体   English

我 go 如何设计这个数据库?

[英]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 ) Userid PK, nameaddress
  • Booking ( id PK, suitcases ) Bookingid 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.

相关问题 我将如何 go 关于在 MySQL 中使用“阵列”? - How would I go about using an "array" in MySQL? 我如何为附加的报告编写SQL? - How would I go about writing the SQL for the attached report? 我将如何插入影响多个表的值? - How would I go about inserting values that affect multiple tables? 您将如何交换连接字符串以访问测试数据库以进行单元测试? - How would you go about swapping a connection string to access a test database for unit testing? 如何在PostgreSQL中的psycopg2 / python中将数据插入到一对多(必须)关系中 - How would I go about inserting data into one-to-many(must) relation, psycopg2/python in PostgreSQL 如何使用更新语句在SQL中将服务价格降低10%? - How would I go about reducing the price of a service by 10% in SQL using an update statement? 我 go 如何加入 SQL 中的多个多对一表? - How would I go about joining multiple many-to-one tables in SQL? 如何将不同SQL表的内容“添加”在一起? - How would I go about “adding” the contents of different SQL Tables together? 如果 DOB 列被加密,我将如何 go 关于计算 MySQL 中每个人的年龄 - If DOB column is encrypted, how would I go about calculating the age of each person in MySQL 我将如何 Go 关于将文本结果聚合到单个临时列中? - How Would I Go About Aggregating Text Results Into A Singular Temporary Column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM