0

I have a 3 tables, Employee, Languages, Employee Languages.

Now, Employee table is a profile table. Nothing special(Id, first name, last name etc.).

Languages table has two columns: Language ID column and Language name column. This table, basically is a list of all languages.

Employee Languages consists of three columns: Employee ID, Language ID and Proficiency.

So, when I want to show employee languages, I have to get language id, then correlate that id to language name and then show it to the end user.

I'm currently thinking about new scenario with two tables:

First would be Employee table.

Second would be Employee Languages, which consists of Employee ID, Language Name and Proficiency.

So, Language name and Proficiency would be populated in front end and would be shown as a drop down list.

My question is which scenario would be much more effective in my case?

3
  • 1
    Why try to use only two tables when you clearly need three tables, as in your current design? What do you think is wrong with your current design?
    – zgguy
    Commented Feb 8, 2016 at 11:58
  • To be honest, I just thought that it looks a little bit clumsy.
    – theo
    Commented Feb 8, 2016 at 12:29
  • 2
    (The alternatives are even more clumsy.)
    – Rick James
    Commented Feb 8, 2016 at 19:43

4 Answers 4

3

Your 2 table design approach can be implemented using a view. This would not compromise your underlying database design based on 3 tables.

Views are under used but often give the best of all worlds.

Expanded:

From your "normalised" 3 table design, which looks OK, you will CREATE VIEW (SELECT Employee ID, Language Name, Proficiency FROM Employee, Languages, Employee_Languages WHERE etc. ). Your application then selects from the view.

0
2

3 tables is best for the following reasons.

  1. You have a lookup table, pulling data from the lookup table is faster.
  2. You can Expand the employee table without worrying the effects on the language table
  3. You can Expand the language table without worrying the effects on the employee table.

You can apply a two column key on the lookup table, making it impossible for employee John Doe to learn English twice.

1

First solution (3 tables) allow you to search of employees with given language in efficient and unambiguous way. The same language name is assigned to different employees (without literal errors like "english"/"Engliish"). It's a better way for developing new functionality in the future.

1

Your question is less about whether to use many-to-many relationships and more about the choice between a surrogate or natural key.

You do need three tables - Employees, Languages and Employee_Languages - but you could choose to use the Language Name as a natural key instead of Language ID as a surrogate key.

The choice of whether to use a natural or foreign key is a pragamatic one made of the basis of familiarity, irreducibility, stability and simplicity. Your question indicates that use of a natural key may be the best for your circumstances. You should analyze all the uses of Languages within your application and decide, given the criteria above, whether the use of a natural or surrogate key would be the best for you.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.