views:

37

answers:

1

Hello!

I want to use tags in my site. How to handle the tags most efficiently?

Is it OK to put every tag in a table (like categories) and than in the post just reference them with their id? (like in wordpress)

A: 

In general, having a lookup table for tags and then referencing them by ID is a good idea, yes. Among other things, it saves storage space - you only need to store the string version of a tag once; the numerical id will almost certainly be shorter.

Tags are generally a many-to-many relation, and thus usually use a layout that consists of 3 tables: the content items table, the tags table, and then a "content-to-tag" mapping table. The first two are fairly straightforward; the third is merely a table where each row is a link between a content item and a tag.

Amber