Reputation: 1457
I have a table that contains a list of words. Each of the words has multiple categories assigned to them. What is the best way to do that?
I do not want to use a set, because the list of categories keeps changing.
I was thinking of having another table that assigns IDs to the categories and then add a field with the list of categories to the table containing the words. Is storing a list of IDs in a text field the "proper" way to do this?
Upvotes: 0
Views: 987
Reputation: 889
You should have three table for this:
here word_id in word_table and cat_id in categories_table is primary key
Upvotes: 2
Reputation: 70
I agree with Biswajit on creating three tables.
word_table (you already have )- word_id, word,... categories_table - cat_id, cat_name, ... word_cat_table - cat_id, word_id
The relationship between first and third table could be 1-Many as one work can be in multipe categories.
Upvotes: 1
Reputation: 3167
You create a table that maps words to categories.
Two columns in the table: categoryID, wordID
Upvotes: 2