OK, then to preserve a single Tasks table you could do this:
* Add a column to Tasks called TaskType, constrained to be 'PERSON' or 'PROJECT'.
* Create a UNIQUE constraint on Tasks(TaskType,Id)
* Create a table PersonTasks like this:
create table PersonTasks
( PersonId REFERENCES Person
, TaskType varchar(6) CHECK (TaskType = 'PERSON')
, TaskId integer
, FOREIGN KEY (TaskType,TaskId) REFERENCES Tasks(TaskType,Id)
);
* Create a similar table ProjectTasks
Now when you create an association between a Person and a Task, you will only be allowed to choose 'PERSON' Tasks:
i.e. this will work:
Code:
insert into PersonTasks(personId,TaskType,TaskId) values (1,'PERSON',101);
but this will not (prevented by the CHECK constraint):
Code:
insert into PersonTasks(personId,TaskType,TaskId) values (1,'PROJECT',202);