I've got a list of synonyms and need to create a database in SQL for it.
I was thinking about using a Relational Database Design, but don't know if it would be the best. There will be a decent amount of traffic using this database.
I was thinking about Table1 would be like
Id
Table2
Id
InterlinkID (Table1 Id)
Word
Would this be the best way? There could be 1 - 20+ linked words. One other problem I see from this setup is If I have 1 word that works as a synonym for more than one word.
Not so great Example of how it will be used, but you get the idea:
Table 1 Id 1 Id 2 Table 2 Id 1 InterlinkID 1 Word One Id 2 InterlinkID 1 Word 1 Id 3 InterlinkID 1 Word First Id 4 InterlinkID 2 Word Two Id 5 InterlinkID 2 Word 2 Id 6 InterlinkID 2 Word Second
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
- nullableUse 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 | NULL
2 | 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With