简体   繁体   English

设计跟踪订单和愿望清单的数据库的最佳方法是什么?

[英]What's the best approach to designing a database that keeps track of orders and wish lists?

The best way to describe this scenario is to use an example. 描述这种情况的最佳方法是使用示例。 Consider Netflix: do they store their orders (DVD's they mail out) in a separate table from their member lists (NOT members table, but a joiner table of members and movies--a list of movies each member has created) , or are orders distinguished by using additional information in the same row of the same table? 考虑Netflix:他们是否将订单(他们寄出的DVD)存储在与成员列表不同的表中(不是成员表,而是成员和电影的连接器表-每个成员创建的电影的列表) ,还是订单?通过在同一表的同一行中使用其他信息来区分?

For those not familiar with Netflix, imagine a service that lets you create a wish list of movies. 对于不熟悉Netflix的用户,可以想象一下一项服务,该服务可让您创建电影的愿望清单。 This wish list is subsequently sent to you incrementally, say two movies at a time. 随后,此愿望清单会逐步发送给您,一次要说两部电影。

I would like to implement a similar idea using a MySQL database, but I am unsure whether to create two tables (one for orders and one for lists) and dynamically move items from the lists table to the orders table (this process should be semi-automatic based on the member returning an item, where before a new one is sent out, a table with some controls will be checked to see if the user is still eligible/has not gone over his monthly limit)... 我想使用MySQL数据库实现类似的想法,但是我不确定是否要创建两个表(一个用于订单,一个用于列表)并将项目从列表表动态移动到订单表(此过程应该是半会根据成员退回商品的情况自动生成,在此情况下,在寄出新商品之前,将检查带有某些控件的表格,以查看用户是否仍然有资格/未超过其每月限额)。

Thoughts and pros and cons would be fantastic! 思想和利弊将是太棒了!

EDIT : my current architecture is: member, items, members_items, what I am asking is if to store orders in the same table as members_items or create a separate table. 编辑 :我当前的体系结构是:成员,项目,members_items,我要问的是将订单存储在与members_items相同的表中还是创建单独的表。

A problem with storing orders in the members table is that there's a variable number (0, 1, or several) of orders per member. 在成员表中存储订单的问题是每个成员有可变数量(0、1或几个)的订单。 The way to do this using a relational database is to have two separate tables. 使用关系数据库执行此操作的方法是拥有两个单独的表。

Moving things from one database table to another to change its status is simply bad practice. 将事物从一个数据库表移动到另一个数据库表以更改其状态只是一种不好的做法。 In a RDBMS, you relate rows from one table to other rows in other tables using primary and foreign key constraints. 在RDBMS中,使用主键和外键约束将一个表中的行与其他表中的其他行相关联。

As for your example, I see about four tables just to get started. 至于您的示例,我仅看到大约四个表。 Comparing this to Netflix, the grand-daddy of movie renting, is a far-cry from reality. 相比之下,电影租借的祖父Netflix却与现实相去甚远。 Just keep that in mind. 要时刻铭记在心。

  1. A User table to house your members. 用户表来容纳您的成员。
  2. A Movie table that knows about all of the available movies. 电影表,该表了解所有可用的电影。
  3. A Wishlist or Queue table that has a one-to-many relationship between a User and Movies. 在用户和电影之间具有一对多关系的“ 愿望清单”或“ 队列”表。
  4. An Order or Rental table that maps users to the movies that are currently at home. 将用户映射到当前在家中的电影的OrderRental表。

Statuses of the movies in the Movie table could be in yet another table where you relate a User to a Movie to a MovieStatus or something, which brings your table count to 6. To really lay this out and design it properly you may end up with even more, but hopefully this sort of gives you an idea of where to begin. 电影表中电影的状态可能在另一个表中,在该表中,您将用户与电影关联到MovieStatus或其他东西,这会使表数增加到6。要真正进行布局和正确设计,您可能最终得到甚至更多,但希望这种方法可以使您了解从何开始。

EDIT: Saw your update on exactly what you're looking for. 编辑:看到您正在寻找的确切更新。 I thought you were designing from scratch. 我以为你是从头开始设计的。 The simple answer to your question is: have two tables. 您的问题的简单答案是:有两个表。 Wishlists (or member_items as you have them) and Orders (member_orders?) are fundamentally different so keeping them separated is my suggestion. 愿望清单(或您拥有的member_items)和订单(member_orders?)是根本不同的,因此我建议将它们分开。

I feel like they would store their movies as follows (simplified of course): 我觉得他们会按照以下方式存储电影(当然是简化的):

tables: 表:

  • Titles 标题
  • Members 会员
  • Order 订购
  • Order_Has_Titles Order_Has_Titles

This way an order which has a foreign key to the Members would then have a pivot table as many orders could have many titles apart of them. 这样,对成员而言具有外键的订单将具有一个数据透视表,因为许多订单中可能会有许多头衔。

When you have a many to many realtionship in the database you then need to create a pivot table: 当数据库中有多对多关系时,则需要创建数据透视表:

Order_Has_Titles:
    ID (auto-inc)
    Order_FkId (int 11)
    Title_FkId (int 11)

This way you're able to put multiple movies apart of each order. 这样,您就可以将多个电影分开放置。

Of course this is simplified, and you would have many other components which would be apart of it, however at a basic level, you can see it here. 当然,这是经过简化的,并且您将拥有许多其他组件,但是在基本级别上,您可以在此处看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在MYSQL数据库中设计Rainfall_data表的最佳方法 - Best approach in Designing Rainfall_data Table in MYSQL Database .net核心数据库托管的最佳方法是什么? - What is the best approach for .net core database hosting? 升级数据库时使用的最佳方法是什么 - What is the best approach to use when upgrading a Database 对于数据库查询,返回与您所关注的人的Twitter推文源类似的结果的最佳查询方法是什么? - What is the best approach for database queries that return results similar to Twitter's feed of tweets by people you follow? 列表中的项目编号-最佳方法? - Numbering Items in Lists - The Best Approach? 将本地数据库sqlite与生产服务器(MySQL)同步的最佳方法是什么? - What is the best approach for sync local database sqlite with Production server (MySQL)? 在 GCP 帐户之间迁移 MySQL 数据库的最佳方法是什么? - What is the best approach to migrate MySQL database between GCP Accounts? 在PHP / MySQL中列出用户最近活动的最佳方法是什么? - What is the best approach to list a user's recent activities in PHP/MySQL? 我应该采用什么最好的方法来解决这个问题 - what's the best approach should i adopt for this php problem 展示 SQL - NoSQL 环境的好处的最佳方法是什么? - What's the best approach to showcase benefits from SQL - NoSQL environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM