Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k 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 (40.4k 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.


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.

Related questions

0 votes
1 answer
asked Jul 13, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories