Don't Understand Sql Server Error

Posted by Jonathan Wood on Stack Overflow See other posts from Stack Overflow or by Jonathan Wood
Published on 2011-01-12T01:40:42Z Indexed on 2011/01/12 1:53 UTC
Read the original article Hit count: 569

I have a table of users (User), and need to create a new table to track which users have referred other users. So, basically, I'm creating a many-to-many relation between rows in the same table.

So I'm trying to create table UserReferrals with the columns UserId and UserReferredId. I made both columns a compound primary key. And both columns are foreign keys that link to User.UserID.

Since deleting a user should also delete the relationship, I set both foreign keys to cascade deletes. When the user is deleted, any related rows in UserReferrals should also delete.

But this gives me the message:

'User' table saved successfully 'UserReferrals' table Unable to create relationship 'FK_UserReferrals_User'. Introducing FOREIGN KEY constraint 'FK_UserReferrals_User' on table 'UserReferrals' 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. See previous errors.

I don't get this error. A cascading delete only deletes the row with the foreign key, right? So how can it cause "cycling cascade paths"?

Thanks for any tips.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about relational-database