推荐的SQL数据库设计用于标签或标记 [英] Recommended SQL database design for tags or tagging
问题描述
我错过了标签的最佳做法?
三个表(一个用于存储所有项目,一个用于所有标签,一个用于两个关系),使用外键正确索引设置在正确的数据库上运行,应该能够正常工作并扩展。
表:项
列:ItemID,标题,内容
表: b $ b列:TagID,标题
表:ItemTag
列:ItemID,TagID
I've heard of a few ways to implement tagging; using a mapping table between TagID and ItemID (makes sense to me, but does it scale?), adding a fixed number of possible TagID columns to ItemID (seems like a bad idea), Keeping tags in a text column that's comma separated (sounds crazy but could work). I've even heard someone recommend a sparse matrix, but then how do the tag names grow gracefully?
Am I missing a best practice for tags?
Three tables (one for storing all items, one for all tags, and one for the relation between the two), properly indexed, with foreign keys set running on a proper database, should work well and scale properly.
Table: Item
Columns: ItemID, Title, Content
Table: Tag
Columns: TagID, Title
Table: ItemTag
Columns: ItemID, TagID
这篇关于推荐的SQL数据库设计用于标签或标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!