This is the relevant table structure:
After which I am running the following queries to add the foreign key restraints:
ALTER TABLE [members].[tbl_FriendInvite]
ADD FOREIGN KEY ([FromMemberID]) REFERENCES [members].[tbl_Member] ([MemberID]) ON DELETE CASCADE ON UPDATE NO ACTION
GO
ALTER TABLE [members].[tbl_FriendInvite]
ADD FOREIGN KEY ([ToMemberID]) REFERENCES [members].[tbl_Member] ([MemberID]) ON DELETE CASCADE ON UPDATE NO ACTION
GO
Trying to run this gives the following error:
Introducing FOREIGN KEY constraint 'FK__tbl_Frien__ToMem__031C6FA4' on table 'tbl_FriendInvite' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
I don't understand what the danger is here. When a row in tbl_Member
is deleted it should then cascade and delete all friend invites which have that MemberID
as one of the FromMemberID
or ToMemberID
columns on tbl_FriendInvite
. Is the fact that it may be deleting multiple Friend Invites the reason it is warning against "multiple cascade paths"? That's exactly what I want!
I am using SQL Server
btw.
Have I made an error in my queries or have I misunderstood how foreign keys work?