There are two tables:
- User
- Address
User contains a reference to Address.
Address contains the columns CreatedBy and ModifiedBy, which is reference to User.
How do I design this database to avoid a cyclic dependency?
There are two tables:
User contains a reference to Address. Address contains the columns CreatedBy and ModifiedBy, which is reference to User. How do I design this database to avoid a cyclic dependency? |
|||||||||||||
|
You don't have a choice but to create the cyclic dependency in 2 operations as below because one table does not exist when you create the first one.
If you wish to avoid cyclic dependency. Then you need to remove one REFERENCES constraint or you can add a DELETE and UPDATE CASCADE reference in one way. You could also implement a TRIGGER if your logic is somewhat complex. |
|||||||||||
|
Instead of searching for tips and tricks (deferred constraints included) I would suggest that you simply design your way out of this "reference lock" -- so try something like this: Facts
Constraints
Logical As far as mandatory address is concerned, verify that on the application layer and wrap the loading statements into a transaction -- that way you'll get all or nothing. |
||||
|