SQL database Structure
The most minimal way of modeling the relationship would be as a single table with three columns:
id
- primary key, integerword
- unique word, should have a unique constraint to stop duplicatesparent_id
- nullable
Use the parent_id
to store the id number of the word you want to relate the current word to. IE:
id | word | parent_id---------------------------1 | abc | NULL2 | def | 1
...shows that abc
was added first, and def
is a synonym for it.
A more obvious and flexible means of modelling the relationship would be with two tables:
WORDS
id
, primary keywordvalue
SYNONYMS
word_id
synonym_id
Both columns in the SYNONYMS
table would be the primary key, to ensure that there can't be duplicates. However it won't stop duplicates in reverse order. But it will allow you to map numerous combinations to have a "spider web" relationship between words, while the single table format would only support a hierarchical relationship.