简体   繁体   English

数据库架构

[英]Database Schema

This problem is very simple i think... 我觉得这个问题很简单......

I dont have experience with big scalable databases, and im working in a project and im facing this design problem: 我没有大型可扩展数据库的经验,我正在一个项目中工作,我面临这个设计问题:

I have a table for subscriptors and have a table for the services they could be subscribed to, both tables will grow, the subscriptors can be subscribed to how many services they want, the problem is to estore the relation subscritor -> service i dont know wich would be the proper way, i think it should be one of this options: 我有一个用于下标的表,并有一个表可以订阅他们可以订阅的服务,两个表都会增长,下标可以订阅他们想要的服务数量,问题是要关系subscritor - > service我不知道这将是正确的方式,我认为它应该是这个选项之一:

  • Create a table per service to estore the subscriptor list. 为每个服务创建一个表以对下标列表进行设置。
  • Create a table for the subscriptors and dinamically add new columns to represent the service. 为下标创建一个表,并以dinamically方式添加新列来表示服务。
  • Create a table for the subscritors and use a Binary Mask to store the list of services the user is subscribed to. 为子查询创建一个表,并使用二进制掩码存储用户订阅的服务列表。

Wich way would be the best and more practical, and scalable solution? 哪种方式是最好,更实用,可扩展的解决方案? any other options are apreciated. 任何其他选择都是apreciated。 thanks beforehand. 先谢谢。

PS: Im using MySQL PS:我正在使用MySQL

This is a classic many-to-many relationship - in relational databases, the standard way to deal with this is one table for each side of the relationship and one to store the links between them - like so: 这是一个典型的多对多关系 - 在关系数据库中,处理这个问题的标准方法是关系的每一面都有一个表,一个存储它们之间的链接 - 就像这样:

Subscriber
----------
SubscriberID (PK)
SubscriberName
etc...

Service
-------
ServiceID (PK)
ServiceName
etc...

SubscriberService
-----------------
SubscriberID (PK)
ServiceID    (PK)

You can do this one... 你可以这样做......

One table for subscriptors
One table for services and 
last one to store which subscriptors have which services...

It would be the best one for your project... 这对你的项目来说是最好的......

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM