Sorry for asking such a dumb question. I'm pretty new to SQL in general.
The question is: I have 2 tables
CREATE TABLE [dbo].[Projects]
(
[name] VARCHAR (30) NOT NULL,
[company] VARCHAR (200) NOT NULL,
[manager] VARCHAR (30) NOT NULL,
[start_date] DATETIME NOT NULL,
[end_date] DATETIME NULL,
PRIMARY KEY CLUSTERED ([name] ASC, [company] ASC),
FOREIGN KEY ([company])
REFERENCES [dbo].[Companies] ([email])
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY ([manager])
REFERENCES [dbo].[Managers] ([username])
);
CREATE TABLE [dbo].[Manager_assign_Regular_Employee_Project]
(
[project_name] VARCHAR (30) NOT NULL,
[company] VARCHAR (200) NOT NULL,
[regular_employee] VARCHAR (30) NOT NULL,
[manager] VARCHAR (30) NOT NULL,
PRIMARY KEY CLUSTERED ([project_name] ASC, [company] ASC, [regular_employee] ASC),
FOREIGN KEY ([project_name], [company])
REFERENCES [dbo].[Projects] ([name], [company])
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY ([regular_employee])
REFERENCES [dbo].[Regular_Employees] ([username]),
FOREIGN KEY ([manager])
REFERENCES [dbo].[Managers] ([username])
);
I want to make sure that one employee doesn't work in more than 2 projects at the same time.
For example :
p1 regular1 STARTDATE=1/1/2017 ENDDATE=1/5/2017
p2 regular1 STARTDATE 1/5/2017 ENDDATE=1/20/2017
These two records are okay to have, but if I add another that intersect with the 2 i.e 3 projects at the same it should be rejected
I tried to do a join between 2 project table and the second one but I failed horribly