[英]Mysql : should i put my data into 1 table or split per user?
This data is for a holiday cottage's simple accommodation calendars. 这些数据适用于度假小屋的简单住宿日历。 The data is simple and stores dates when each cottage is booked. 数据很简单,并存储每个小屋预订的日期。
The cols would be cottage_id, booked_from_date, booked_until_date
and I would expect around 60 rows per user per year * 200-300 users. cols将是cottage_id, booked_from_date, booked_until_date
,我预计每个用户每年约60行* 200-300个用户。
I should put this is one table right? 我应该把这是一张桌子吧?
cottage_id, cottage_id,
address?, 地址?,
other info... 其他信息......
user_id, 用户身份,
name, 名称,
other info... 其他信息......
cottage_id, cottage_id,
user_id, 用户身份,
from_date, 从日期,
to_date 至今
Yes , this should be placed in a single table (for all cottages). 是的 ,这应放在一张桌子上(适用于所有别墅)。
You will run into a whole world of hurt when you start placing data that should be in a single table (that can be seperated by a defining type/id) into seperate tables. 当您开始将应该在单个表中的数据(可以通过定义类型/ ID分隔)放入单独的表中时,您将遇到整个受伤的世界。
Just think of how you are to write a query to retrieve availability accross all units, for a given date, accross 10-40 or more units? 想一想你是如何编写一个查询来检索所有单位的可用性,在给定的日期,10-40或更多单位?
Normalizing the table into a MANY to MANY structure is perfectly normal, seperating Cottages from Users and linked by a table CottageUsers with the booked dates. 将表规范化为MANY到MANY结构是完全正常的,从用户分离Cottages并通过表CottageUsers与预订日期链接。
I think Randy's answer is good... another idea to add to his would be to use a calendar table like: 我认为兰迪的答案很好......另外一个想法就是使用日历表:
COTTAGE_CALENDAR COTTAGE_CALENDAR
Add a single row for each day of booking and make the cottage_id and date fields a combined primary key....then you'll prevent overbooking... (adding the reservation_id to the COTTAGE_RESERVATION table that Randy built, for the relational data link).... 为预订的每一天添加一行,并将cottage_id和日期字段作为组合主键....然后您将防止超量预订...(将reservation_id添加到Randy为关系数据链接构建的COTTAGE_RESERVATION表中)....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.