I have the following structure:
- Each person has concrete area
- Each project has concrete area and each project has concrete person.
- All fields are not nullable (one and only one relationship)
Standard "live" situation, business-logic is correct. DB is correct too and works fine. But when I add cascade deleting for each of these relationship of course I get the error:
'Persons' table
- Unable to create relationship 'FK_Persons_Areas'.
Introducing FOREIGN KEY constraint 'FK_Persons_Areas' on table 'Persons' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
I understand why it happened (cascade deleting). For example, if Area is deleted, all projects, which has this AreaID, should be deleted and each persons, which has this AreaID, should be deleted and then all Projects, which have deleted persons should be deleted... How to solve this problem? I tried to add one more table named ProjectAreas:
but this isn't solving the problem. Also, not having clear understanding that Project has one and only one area.
Second question - is it really necessary to solve this problem? Maybe schema with 3 tables is enough and problem with deleting should be solved on application level?