views:

161

answers:

3

I have a problem with a many-to-many relation in my tables, which is between an employee and instructor who work in a training centre. I cannot find the link between them, and I don't know how to get it. The employee fields are:

  • employee no.
  • employee name
  • company name
  • department job title
  • business area
  • mobile number
  • ext
  • ranking

The Instructors fields are

  • instructor name
  • institute
  • mobile number
  • email address
  • fees
+7  A: 

in a many-to-many relationship the relationships will be in a 3rd table, something like

table EmployeeInstructor 
    EmployeeID
    InstructorID

to find all the employees for a specific instructor, you'd use a join against all three tables.

Jimmy
thanks for helping jimmy but i told my teacher the same thing u said she is like that the information for the EmployeeInstructor the fields in this table are few i need more fields
+4  A: 

First of all, you will need a unique key in both tables. The employee number may work for the employee table, but you will need another for the instructor table. Personally, I tend to use auto incrementing identity fields called ID in my tables. This is the primary key. Second, create a new table, InstructorEmployee. This table has two columns, InstructorID and EmployeeID. Both fields should be indexed. Now you can create an association between any Employee and any Instructor by creating a record which contains the two IDs.

Matthew
+5  A: 

Or more likely there will be classes involved --

Employee takes Class Instructor teaches Class

so you'll have and EmployeeClass table,
an InstructorClass table,

and join through them. And Class needs to be unique, or else you'll need

Class is taught in Quarter on ClassSchedule

and end up joining EmplyeeClassSchedule to InstructorClassSchedule.

This ends up being one of your more interesting relational designs pretty quickly. If you google for "Terry Halpin" and "Object Role Modeling", this is used as an illustrative situation in the tutorial.

le dorfier
yeah, this makes more sense than a simple many/many relationship between employees and instructors
Jimmy
+1 for seeing the problem through the question!
Dan Vinton
Iteresting that you mention Terry Halpin. I used the Object Role Modeling feature of Visio for Architects that came with Visual Studio 2005 Architect. It made quick work of creating databases from business requirements.
Matthew
Microsoft still offers an unsupported but perfectly workable version of the same thing as Visiomodeler for free. you can google for it.
le dorfier