Hello,
I am designing a table where employees can also be managers, giving a recursive relationship. Obviously managers don't need a manager, but all employees have one. I am thinking about creating a table for managers.
The Employees table will look like this
CREATE TABLE Employee
(EmployeeID MEDIUMINT NOT NULL,
EmployeeFirstName VARCHAR(20) NOT NULL,
EmployeeLastName VARCHAR(20) NOT NULL,
CONSTRAINT Employee_PK PRIMARY KEY(EmployeeID)
)
ENGINE=InnoDB;
I am not sure exactly how to create a Manager's table, but was thinking two columns as follows. Then creating referential integrity checks between both columns and the Employee(EmployeeID) column.
CREATE TABLE ManagerEmployee
(ManagerEmployeeID MEDIUMINT NOT NULL,
EmployeeID MEDIUMINT,
CONSTRAINT Employee_PK PRIMARY KEY (EmployeeID, ManagerEmployeeID));
Not sure if this is the best way to do it though. No historical data about past managers will be needed. I could just leave the ManagerEmployeeID column in the Employee table and allow NULL values, which would take care of those without managers. I am interested in how others would do this and why.