I am designing a dictionary-like program which stores (and displays) a few example sentences of the given word. One way to design a SQL database for such problem is to create a table with two columns word and example and then for each example sentence add a new row with the repeated word in the column word. Is this approach common and efficient? I was also thinking of dynamically creation of a table of examples for each word and then relate the table to the word somehow. Is this approach better than previous one?
|
|
|||
|
|
migrated from stackoverflow.com Jan 11 at 7:39
|
You could go 1 step further from the other suggestions and take the example sentance into a new table as well. As a sentance is made up of many words the same sentance could be used for different words.
When selecting a word and all the sample sentances you just need to join the tables:
|
|||||||||||||
|
|
It sounds like you would need two tables:
And
(or however you'd like to appropriately name them). This approach prevents storing each word multiple times in the same table. To query for all examples for a word, you add a
|
|||
|
|
|
I would have 2 tables: Word: word_id, word Then Example: word_id,example_sentence This will likely be more efficient in terms of storage since you only need 4 bytes to store an id and possibly many more to store duplicates of a word. |
|||||||
|
