2

enter image description here

I think the design is straightforward so no explanation is required.

Question: Is there a way to inditcate the language of the name column in courses table? Maybe to link it with the languages table?

Edit: Or maybe separate the name-language pare in another table with id and reference it in courses table? Edit2: Course language and Name langauge may be different

1
  • 1
    This database design is A correct B: irreducable. Commented Nov 10, 2011 at 15:55

3 Answers 3

1

Question: Is there a way to inditcate the language of the name column in courses table? Maybe to link it with the languages table?

There's no need. The following query will give you what you want:

SELECT c.name, COALESCE(l.name,'default') as language
FROM courses c
LEFT JOIN courses_has_languages cl ON (cl.courses_course_id = c.course_id)
LEFT JOIN languages l ON (l.language_id = cl.languages_language_id)

Of source it would be even better if you just rename your column names so the query can be rewritten to:

SELECT c.name, COALESCE(l.name,'default') as language
FROM courses c
LEFT JOIN courses_has_languages cl ON (cl.course_id = c.id)
LEFT JOIN languages l ON (l.id = cl.language_id)

But that's just my preference.

Sign up to request clarification or add additional context in comments.

2 Comments

Thats just the default naming from MySQL Workbench.
@abruski, I hate that naming scheme, because it forces you to type until your fingers are blue and it insults a person's intelligence.
0

If I understand you it sounds like you're on the right track. Make language_id a foreign key in the courses table that points back to languages.

1 Comment

Course language and name language can be different.
0

Assuming that the diagram correctly models the data then no, you do not need any additional relationships.

Instead, you will retrieve the languages for a course by JOINing the tables in a SELECT statement. If this is an operation you will perform frequently, you can encapsulate that SELECT statement by CREATEing a VIEW.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.