简体   繁体   中英

Linking Two Foreign Keys to one Primary Key

I have two tables, a Photographer and an Influences table. In the Influences table, a Photographer is able to influence another Photographer.

Relational Schema:

Here is my Diagram in SQL:

Instance Example:

My issue is when I try to delete Photographer Tom, since he influences Jason (as shown in Influences table), I get a error stating:

The DELETE statement conflicted with the REFERENCE constraint "FK_Influences_Photographer1". The conflict occurred in database "jma59", table "dbo.Influences"

If Tom was in the column EPName of the Influences table, I have no issue deleting it. I know that this is a foreign key issue but I am not sure how to handle this situation. I created two separate foreign keys that reference to the Photographer primary key. But the problem is that I cannot make it so that both foreign keys cascade on update and delete.

First foreign key is EPName and EPBDate referencing to PName and PBDate of Photographer

Second foreign key is RPName and RPBDate referning to PName and PBDate of Photographer as well.

The error is:

Unable to create relationship 'FK_Influences_Photographer1'. Introducing FOREIGN KEY constraint 'FK_Influences_Photographer1' on table 'Influences' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

Any advice is greatly appreciated!

您可以考虑使用触发器而不是级联删除来实现参照完整性: https : //support.microsoft.com/en-gb/help/321843/error-message-1785-occurs-when-you-create-a-外键约束-THA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM