Lets say I have two tables - User and Post
I introduced a customized Join table Vote to have a many-to-many relationship between User and Post.
The tables have following structure:
- User (UseId, Name)
- Post (PostId, UserId, Content)
- Vote(Id, UserId, PostId, Value)
Notes:
- The emphasized columns of each table is a
PK. - The
UserIdin Post is aFKto User table. - The
UserIdandPostIdcolumns in Vote table areFKto the respective tables. - Other columns like
Value,Content,Name, etc. are varchar.
Considering the above design is appropriate (if not, suggestions are welcomed :) .....
What I want is:
- If a row in Post Table is deleted, the related row in Vote should also be deleted.
- If a row in User Table is deleted, the related row in Vote should also be deleted.
- If a row in User Table is deleted, the related row's
UserIdcolumn in Post should be set to NULL.
Can I achieve such kind of relationships, without any Cyclic-Redundancy? If yes, How?
UPDATE:
Check out this awesome answer if you too have faced multiple cascade paths: