mysql - How should I store tags for domain names in a database? -
lets google.com has tags called:
search,google,searchengine,engine,web
facebook has tags called:
facebook,social,networking,friends,community
how should store both domain , respective tags in database?
you should create 3 tables store stuff:
domains: id | name
tags: id | name
domains_tags: tag_id | domain_id
domains:
id | name ------------------ 1 | google.com 2 | stackoverflow.com
tags:
id | name ------------------ 1 | web 2 | lol 3 | facepalm.jpg
domains_tags:
domain_id | tag_id ------------------ 1 | 1 1 | 2 2 | 3
in sample there 2 tags related google
domain , 1 tag related so
and each relation need add 1 more record domains_tags
store relation between domain , particular tag.
this technique named many-to-many
as proposed in answer - can add additional field domains
named tags
, store tags there separated comma, solution weird, since you'll troubles when you'll need have analytics/statistics/searches domains , tags. reason follow idea "cache" current domain's tag list display, as addition (not replacement!!) solution i've given first.
Comments
Post a Comment