【发布时间】:2020-02-11 20:00:40
【问题描述】:
嘿,我只是想为照片创建一个表。它有一个可以存储多种类型的列,就像它属于(野生动物、自然、冒险..等)和标签一样,它有自己的表用于表更新记录
【问题讨论】:
标签: mysql database database-design entity-relationship
嘿,我只是想为照片创建一个表。它有一个可以存储多种类型的列,就像它属于(野生动物、自然、冒险..等)和标签一样,它有自己的表用于表更新记录
【问题讨论】:
标签: mysql database database-design entity-relationship
photos:
id,
who, when, where
tags: -- this is a many:many mapping table
photo_id, -- join to photos.id
tag VARCHAR(99)
PRIMARY KEY(tag, photo_id),
INDEX(photo_id, tag)
tag 栏目可能有野生动物、自然、冒险等
如果通过标签,您的意思是category,而一张照片只属于一个类别,那么它的做法会有所不同:将category(或category_id)添加到photos。这是1:many 关系。
【讨论】:
您可以继续保留 6 列。
photo_tag_id、photo_tag、photo_links、photo_created_date、photo_updated_date
在将数据存储在 MySql 中时,该表在 photo_tag_id 和 photo_tag 上是唯一的,主索引在 photo_tag_id 上,辅助索引在 photo_tag 列上。您可以随时根据 photo_tag_id 和 photo_tag 的过滤条件进行更新。
【讨论】: