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
UserId
in Post is aFK
to User table. - The
UserId
andPostId
columns in Vote table areFK
to 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
UserId
column 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: