M
M
MIsternik2015-01-05 13:26:43
Database
MIsternik, 2015-01-05 13:26:43

How to correctly design a relationship between database tables (see description)?

There is a table with languages ​​between which there can be a translation.
Approximately with the following structure:
id name
You need to create a table of words with translations. The same word can be translated differently into different languages.
Therefore, it is necessary to link the word itself, the language "from which" and the language "into which" we are translating.
For me, the obvious solution is a composite key of three fields. But is it normal that 2 of these fields are secondary keys of the same table.
Is there any other solution for such situations?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-01-05
@Rsa97

Isn't that easier?

CREATE TABLE `words` (
  `word_id` INT NOT NULL,
  `language_id` INT NOT NULL,
  `word` VARCHAR(45) NULL);

At the same time, one word in different languages ​​must have the same word_id. Then, having found the word_id of a word in the current language, you can use the pair (word_id, language_id) to find its variants in another language.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question