0 votes
1 view
in SQL by (21k points)

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?

1 Answer

0 votes
by (37.6k points)

Three tables (one for storing all items, next for all tags, and the third for the relations between the two), only when properly indexed with foreign keys and appropriately scaled, would run well on a database.

 Query:

Table 1: Item

Columns: ItemID, Title, Content

Table 2: Tag

Columns: TagID, Title

Table 3: Item_Tag

Columns: ItemID, TagID

This works will for tagging.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...