简体   繁体   English

Mysql:我应该将我的数据放入1个表中还是按用户分割?

[英]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 COTTAGE


cottage_id, cottage_id,
address?, 地址?,
other info... 其他信息......

USER 用户

user_id, 用户身份,
name, 名称,
other info... 其他信息......

COTTAGE_RESERVATION COTTAGE_RESERVATION

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

  • cottage_id cottage_id
  • date 日期
  • reservation_id reservation_id

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.

相关问题 PHP和MySQL-在显示给用户之前,从数据库中提取数据时是否应验证/清除数据? - PHP and MySQL - Should I validate/sanitize my data when pulling it from my database before displaying to user? 我应该拆分mySQL表吗? - Should I split the mySQL tables? CakePHP应用程序的初始数据应该放在哪里? - Where should I put the inicial data for my CakePHP application? 如何为每个用户在表中放置一个默认图像? - how can i put a default image in my table for every user? 为什么即使在幻灯片放映中按条件显示每3个数据也显示我的所有数据? - why all of my data is showed even i've put the conditional to show it per 3 data in a slideshow? 如何将这些多个值存储在MySQL表中? - How should I store these multiple values in my MySQL table? 在将字符串插入 mysql 表之前,我应该如何格式化我的字符串? - How should I format my string before inserting it into a mysql table? MYSQL应该使用2个查询或将它们添加到我的新表中 - MYSQL should i use 2 querys or add them to my new table 如何将用户喜欢的页面数据存储到Mysql数据库中 - How should I store the data of the liked pages by a user into Mysql database 如何使用MySQL和PHP格式化按用户输入日期从表中获取数据 - How to fetch data from table as per user input date with formatting using MySQL and PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM