How to design a database for translation dictionary?

前端 未结 1 1070
攒了一身酷
攒了一身酷 2020-12-14 13:13

I have database with words and phrases from for exp. English to 15 other languages, and also for every language in that list to other 15. For one pair they are sort for now

相关标签:
1条回答
  • 2020-12-14 14:17

    With separate table for each language, you'd need a large number of junction tables to cover all the possible translation combinations. On top of that, adding a new language would require adding more tables, rewriting the queries, client code etc.

    It's better to do it in a more generalized way, similar to this:

    enter image description here

    Regarding the TRANSLATION table, I propose to also create a CHECK (WORD_ID1 < WORD_ID2) and create an index {WORD_ID2, WORD_ID1} (the opposite "direction" from the PK), and represent the both directions of the translation with only one row.

    Consider clustering the TRANSLATION table if your DBMS supports that.

    Also need it alphabetically all time

    The query...

    SELECT * FROM WORD WHERE LANGUAGE_ID = :lid ORDER BY WORD_TEXT
    

    ...can use the index underneath the UNIQUE constraint {LANGUAGE_ID, WORD_TEXT}.

    0 讨论(0)
提交回复
热议问题