什么是在数据库中存储标签的最有效的方法? [英] What is the most efficient way to store tags in a database?

查看:610
本文介绍了什么是在数据库中存储标签的最有效的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上实施了一个标记系统,类似于一个stackoverflow使用,我的问题是 - 最有效的方式来存储标记,以便他们可以搜索和过滤?

I am implementing a tagging system on my website similar to one stackoverflow uses, my question is - what is the most effective way to store tags so that they may be searched and filtered?

我的想法是这样:

Table: Items
Columns: Item_ID, Title, Content

Table: Tags
Columns: Title, Item_ID

慢?有更好的方法吗?

推荐答案

一个项目将有很多标签。一个标签将属于许多项目。这意味着我很可能需要一个中间表来克服多对多的障碍。

One item is going to have many tags. And one tag will belong to many items. This implies to me that you'll quite possibly need an intermediary table to overcome the many-to-many obstacle.

有点像:


表:项目

列:Item_ID,Item_Title,内容

Table: Items
Columns: Item_ID, Item_Title, Content

br>
列:Tag_ID,Tag_Title

Table: Tags
Columns: Tag_ID, Tag_Title

表:Items_Tags

列:Item_ID,Tag_ID

Table: Items_Tags
Columns: Item_ID, Tag_ID

这可能是因为你的网络应用程序是疯狂的流行,需要在路上取消规范,但它太过于混乱的水域太早。

It might be that your web app is insanely popular and need denormalising down the road, but it's pointless muddying the waters too early.

这篇关于什么是在数据库中存储标签的最有效的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆