![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Imagine you have a Table Employees, with values ID (PK), Name, Supervisor (FK). Supervisors are also employees, so 'Supervisor' is a self-referencing foreign key to ID. We realise that supervisors supervise more than one employee. Now imagine that employees can have more than one supervisor - thus, a many-to-many, self-referencing foreign key. How can this be done? (The example is for discussion's sake - in reality, my table is Tag ID, Tag Name, and Parent, etc.) Many thanks |
#3
| |||
| |||
|
|
Imagine you have a Table Employees, with values ID (PK), Name, Supervisor (FK). Supervisors are also employees, so 'Supervisor' is a self-referencing foreign key to ID. We realise that supervisors supervise more than one employee. Now imagine that employees can have more than one supervisor - thus, a many-to-many, self-referencing foreign key. How can this be done? (The example is for discussion's sake - in reality, my table is Tag ID, Tag Name, and Parent, etc.) Many thanks |
#4
| |||
| |||
|
|
isporter (AT) gmail (DOT) com> wrote in message news:1159007214.155843.67870 (AT) m73g2000cwd (DOT) googlegroups.com... Imagine you have a Table Employees, with values ID (PK), Name, Supervisor (FK). Supervisors are also employees, so 'Supervisor' is a self-referencing foreign key to ID. We realise that supervisors supervise more than one employee. Now imagine that employees can have more than one supervisor - thus, a many-to-many, self-referencing foreign key. How can this be done? (The example is for discussion's sake - in reality, my table is Tag ID, Tag Name, and Parent, etc.) Many thanks The term I'm familiar with is "reflexive relationship" rather than "self referencing key", but that's just a matter of terminology. To deal with your question, the answer is the same as it would be for any other kind of many to many relationship: you need another table, say table Supervision with columns (EmployeeId (FK) and SupervisorId (FK)). The PK of this table is the entire row. EmployeeId references Employees.ID, and so does SupervisorID, but they don't reference the same row. (unless an employee is his own supervisor). The most common situation where a table like this is needed is parts explosion. When parts are components of other parts, the relationship is many-to-many. HTH. |
#5
| |||
| |||
|
|
Imagine you have a Table Employees, with values ID (PK), Name, Supervisor (FK). Supervisors are also employees, so 'Supervisor' is a self-referencing foreign key to ID. We realise that supervisors supervise more than one employee. Now imagine that employees can have more than one supervisor - thus, a many-to-many, self-referencing foreign key. How can this be done? (The example is for discussion's sake - in reality, my table is Tag ID, Tag Name, and Parent, etc.) Many thanks It's a manytomany relationship. It just so happens to be |
#6
| |||
| |||
|
|
isporter (AT) gmail (DOT) com wrote: [...] - supervisors are all those in the employees_supervisors whose supervisor_id is NULL |
#7
| |||
| |||
|
|
strawberry wrote: isporter (AT) gmail (DOT) com wrote: [...] - supervisors are all those in the employees_supervisors whose supervisor_id is NULL IMO both attributes in employees_supervisors should be "not null", and together they are the p.k. of the table. A *proper* supervisor is those emploees that exist as supervisors but not as employees in employees_supervisors /Lennart |
#8
| |||
| |||
|
|
strawberry wrote: isporter (AT) gmail (DOT) com wrote: [...] - supervisors are all those in the employees_supervisors whose supervisor_id is NULL IMO both attributes in employees_supervisors should be "not null", and together they are the p.k. of the table. |
|
A *proper* supervisor is those emploees that exist as supervisors but not as employees in employees_supervisors |
#9
| |||
| |||
|
|
"Lennart" <Erik.Lennart.Jonsson (AT) gmail (DOT) com> wrote in message [...] A *proper* supervisor is those emploees that exist as supervisors but not as employees in employees_supervisors In most companies, supervisors have supervisors, although they may have the title "managers" or something like that. The employee_supervisors table is capable of recording the structure of a tree structured hierarchical supervision relationship all the way up to the CEO. |
#10
| |||
| |||
|
|
How can this be done? |
![]() |
| Thread Tools | |
| Display Modes | |
| |