Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
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.7k 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.

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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...