Sorry! The database was designed poorly and I'm just triyng to get this working with what I'm given
Here's the schema. I removed most unrelated columns from this.
UserBase Table
CREATE TABLE UserBase(
UserBaseId int IDENTITY(1,1),
Created_By nvarchar(64) DEFAULT CURRENT_USER NOT NULL,
Created_Date datetime DEFAULT GETDATE() NOT NULL,
Modified_By nvarchar(64) NULL,
Modified_Date datetime NULL,
CONSTRAINT PK_UserBase PRIMARY KEY NONCLUSTERED (UserBaseId)
)
go
Employees Table
CREATE TABLE Employees(
UserBaseId int NOT NULL,
DepartmentId int NULL,
CONSTRAINT PK_Employees PRIMARY KEY NONCLUSTERED (UserBaseId)
)
go
ALTER TABLE Employees ADD CONSTRAINT FK_Employees_UserBase
FOREIGN KEY (UserBaseId)
REFERENCES UserBase(UserBaseId)
go
ALTER TABLE Employees ADD CONSTRAINT FK_Employees_Departments
FOREIGN KEY (DepartmentId)
REFERENCES Departments(DepartmentId)
go
Departments Table
CREATE TABLE Departments(
DepartmentId int IDENTITY(1,1),
DepartmentName nvarchar(100) NOT NULL,
Created_By nvarchar(64) DEFAULT CURRENT_USER NOT NULL,
Created_Date datetime DEFAULT GETDATE() NOT NULL,
Modified_By nvarchar(64) NULL,
Modified_Date datetime NULL,
CONSTRAINT PK_Departments PRIMARY KEY NONCLUSTERED (DepartmentId)
)
go
Supervisors Table
CREATE TABLE Supervisors(
SupervisorId int IDENTITY(1,1),
DepartmentId int NOT NULL,
Effective_Date datetime NULL,
CONSTRAINT PK_Supervisors PRIMARY KEY NONCLUSTERED (SupervisorId)
)
go
ALTER TABLE Supervisors ADD CONSTRAINT FK_Supervisors_Departments
FOREIGN KEY (DepartmentId)
REFERENCES Departments(DepartmentId)
go
Basically Employees Entity inherit from UserBase in LLBL, since all Employees are Users. Each Employee belongs to a department. Each entry in the Supervisor table indicates a supervisor belonging to a department.
It does sound confusing but I hope you can understand this.