[英]Database design for unknown number of lists with a variable amount of items on each of them?
I'd like to design something that would allow users to put lists together of, let's say, grocery items. 我想设计一些东西,使用户可以将杂货类物品的清单放在一起。 If each user can have multiple lists (ie not a set amount) and those lists all have a variable number of items on them (again, not set) while some items appear on several different lists , how do I create a database without being horribly redundant? 如果每个用户可以有多个列表(即不是固定数量),并且这些列表上都有可变数量的项目(再次未设置),而某些项目出现在几个不同的列表中 ,那么我如何创建数据库而又不至于感到恐惧多余的?
I'm completely new to this kind of problem, not having put together any complex database before, and have no idea where to start. 对于这种问题,我是全新的,以前没有组装过任何复杂的数据库,也不知道从哪里开始。 This is what I came up with as an example, but I doubt this is the right way of doing things: 这是我想出的一个例子,但是我怀疑这是正确的处理方式:
Any help or ideas would be much appreciated! 任何帮助或想法将不胜感激!
You can create join table LIST_LINK_ITEM
between three tables 您可以在三个表之间创建join table LIST_LINK_ITEM
Her primary key is : composition of three primary keys 她的主键是:三个主键的组成
Looks like you need something similar to this: 看起来您需要类似以下内容:
A list is private to user, but an item can be shared among multiple lists: 列表是用户专用的,但一个项目可以在多个列表中共享:
I have used identifying relationship between USER and LIST in the diagram above, producing more "natural" keys in the "downstream" tables which: 我在上图中使用了USER和LIST之间的标识关系,在“下游”表中产生了更多“自然”键,这些键:
The design using non-identifying relationship between USER and LIST (producing "slimmer" keys) would look like this: 使用USER和LIST之间的非标识关系(产生“ slimmer”键)的设计如下所示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.