我应该如何在数据库中存储域名标签?
假设 google.com 的标签名为:
search,google,searchengine,engine,web
Facebook 的标签名为:
facebook,social,networking,friends,community
我应该如何将域及其各自的标签存储在数据库中?
Lets say google.com has tags called:
search,google,searchengine,engine,web
Facebook has tags called:
facebook,social,networking,friends,community
How should I store both the domain and its respective tags in a database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该创建 3 个表来存储所有这些内容:
标签:id |名称
domains_tags: tag_id | domain_id
domains:
tags:
domains_tags:
在此示例中,有 2 个与
google
域相关的标签和一个与SO
相关的标签,对于每个关系,您需要添加
domains_tags
中还有一条记录,用于存储域和特定标签之间的关系。该技术被命名为 Many-To-Many
正如另一项中提出的答案 - 您还可以向名为
tags
的domains
添加额外的字段,并在其中存储用逗号分隔的标签,但这个解决方案很奇怪,因为当您需要对域和标签进行一些分析/统计/搜索。遵循这个想法的唯一原因是“缓存”当前域的标签列表以仅显示,作为我首先给出的解决方案的补充(而不是替换!!)。You should create 3 tables for store all this stuff:
domains: id | name
tags: id | name
domains_tags: tag_id | domain_id
domains:
tags:
domains_tags:
In this sample there are 2 tags related to
google
domain and one tag related toSO
And for each relation you need to add one more record to
domains_tags
that will store relation between domain and particular tag.This technique is named Many-To-Many
As proposed in another answer - you can also add additional field to
domains
namedtags
and store tags there separated by comma, but this solution is weird, since you'll get troubles when you'll need to have some analytics/statistics/searches about domains and tags. The only reason to follow this idea is to "cache" current domain's tag list to just display, as an addition (not replacement!!) to the solution I've given first.听起来像是一个非常简单的 2 列表 |域名 |标签|
Sounds like a very simple table with 2 columns | Domain | tag |