oxuser
oxuser

Reputation: 1327

Asking for help to refactor SQLite database design

I have two tables : products and tags.

products

key | name | description | url

tags

key2 | tag | tag description

Association

eg a product "plate" has the tags "ceramic", "white", "delicate", etc associated with it.

I don't know however how to create a many-to-many representation.

What's the best way to store these tag associations? Create a tags field in products? Or another table? Thanks!

Edit: tags are many-to-many, thanks S.Lott

Upvotes: 1

Views: 142

Answers (2)

S.Lott
S.Lott

Reputation: 391854

One tag can be associated with many products and each product has one or more tags associated with it.

That's not a one-to-many. That's many-to-many.

Google "Association Table" or "Junction Table" for numerous examples.

http://en.wikipedia.org/wiki/Junction_table

http://www.youtube.com/watch?v=P_nhBKs25DQ

Upvotes: 3

ToddBFisher
ToddBFisher

Reputation: 11590

I would go with an additional table named (productTags: key, productKey, tagKey) that would map the two tables together.

Upvotes: 1

Related Questions