Relating two database tables (associating an employee with an activity)

此生再无相见时 提交于 2019-12-11 19:28:46

问题


I am trying to develop a database to store data collected by a web based application that tracks employee activities. I have an employee table that looks like this

Employee
--------
id
name
position
email

And and multiple activity tables, each with different columns. An example of one:

OutreachAndTraining
-----
id
date
county
city
type
...

ProfessionalDevelopment
------
id
date
comments

I want to be able to keep track of which employees were a part of each activity but only want to log the activity itself once. What is the best way to associate multiple employees with one activity? Will I have to create a separate table for each activity to store employee IDs and activity IDs?


回答1:


Assuming an employee can take part in more than one activity, what you have here is an N:M relationship between employees and activities, which is modeled with the additional "link" table per each relationship:


If you have many kinds of activities, you may consider inheritance (aka. category, generalization, subtype or class hierarchy), to minimize the number of relationships (and therefore "link" tables):

For more information on inheritance, search for "Subtype Relationships" in ERwin Methods Guide.



来源:https://stackoverflow.com/questions/10096397/relating-two-database-tables-associating-an-employee-with-an-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!