问题
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