介绍FOREIGN KEY约束! ! ! [英] Introducing FOREIGN KEY constraint! ! !

查看:157
本文介绍了介绍FOREIGN KEY约束! ! !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我插入了一些外键,但是这个没有用。

i在这个表中插入了另一个外键。

i inserted some foreign key but this one not work.
i inserted another foreign key in this table.

alter table ROOM
   add constraint FK_ROOM_REFERENCE_USER foreign key (USERID)
      references "USER" (USERID)
      on update cascade
      on delete cascade;





错误是:





the error is :

Msg 1785, Level 16, State 0, Line 1
Introducing FOREIGN KEY constraint 'FK_ROOM_REFERENCE_USER' on table 'ROOM' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint or index. See previous errors.





当我说它没有动作它会工作

但是在级联上没有!



我尝试了什么:



i插入所有表格和外国钥匙,但没有插入两个外键。

房间表我有3个外键。

其中一个插入。

我的两个号码我编写的其中一个代码无效。

我该怎么办?



when i put it no action it will be work
but on cascade no!

What I have tried:

i inserted all of tables and foreign key but two foreign key not inserted.
in room table i have 3 foreign key.
one of them inserted.
two number of my code not working that one of them i wrote up.
what should i do?

推荐答案

首先查看所有表格中的数据,并注意已经存在的外键。最可能的原因是你已经建立了一个存在循环的关系,因此TableA有一个FK到TableB,而TableB有一个FK到TableA(或通过TableC等) - 所以级联最终试图循环,因为从一个表中删除导致第二个删除,导致第一个删除,依此类推。
Start by looking at your data in all tables, and pay attention to what foreign keys already exist. The most likely reason for this is that you have set up a relationship where a loop exists, so that TableA has an FK to TableB, and TableB has an FK to TableA (or via TableC, etc) - so the cascades end up trying to loop because deleting from one table causes a delete on the second, which causes the first to delete, and so forth.


您创建的最后一个外键约束引入了表之间的循环引用。

如果DELETE / UPDATE操作被设置为多于一个关系的NO ACTION以外的任何内容,则不接受循环引用。

您可能必须遵循建议在错误消息中给出。或者,您必须修改数据库的设计以摆脱循环引用;我们无法在此阶段提供任何其他建议,因为我们不知道您的数据库的实际架构。



亲切。
The last foreign key constraint you created introduced a circular reference between your tables.
Circular references are not accepted if the DELETE/UPDATE actions are set to anything else than "NO ACTION" for more than one relation.
You may have to follow the advise given in the error message. Or, you would have to modify the design of your database to get rid of the circular reference; we cannot provide any other advise at this stage, as we do not know the actual architecture of your database.

Kindly.


这篇关于介绍FOREIGN KEY约束! ! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆