0

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?

2
  • Please post something you have tried so as the question is better understood. Commented Sep 4, 2013 at 16:58
  • Can't your IDs use an integer field? Commented Sep 4, 2013 at 16:59

3 Answers 3

2

You create a table that maps words to categories.

Two columns in the table: categoryID, wordID

Sign up to request clarification or add additional context in comments.

Comments

2

You should have three table for this:

  1. word_table (you already have )- word_id, word, ...
  2. categories_table - cat_id, cat_name, ...
  3. word_cat_table - cat_id, word_id

here word_id in word_table and cat_id in categories_table is primary key

2 Comments

Is it possible to link the first and third table so that everytime a word is added to table 1 its ID is automatically added to table 3?
@eevaa: Impossible. How do you tell to which category it would be added then? Biswajit: Please, mark the primary keys... it is essential to the answer.
1

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.

1 Comment

Actually, instead of could be I'd say must be in order to transform the many to many conceptual relationship into the physical level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.