在一个表中删除外键级联的倍数 [英] multiple on delete cascade of foreign key in one table
问题描述
我有两个表,user_info,并遵循Primary-foregin关系.
像这样:
I have two tables,user_info and follow with Primary-foregin relationship
like this:
create table user_info
(
ID bibigint gint identity(1,1) not null primary key
Name varchar(30),
.....
.....
)
create table follow
(
following bigint not null references user_info(ID) on delete cascade,
follower bigint not null references user_info(ID) on delete cascade,
CONSTRAINT uk_follow UNIQUE (following,follower)
)
输出:
成功创建了第一个表
但是当我运行创建跟随表时,错误就抛出了我
Output:
First table is sucesfully created
but when i run to create follow table then error is thrown to me
Msg 1785, Level 16, State 0, Line 1<br />
Introducing FOREIGN KEY constraint ''FK__foll__follo__0AF29B96'' on table ''follow'' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.<br />
Msg 1750, Level 16, State 0, Line 1
无法创建约束.请参阅先前的错误.
注意:但是我想在以下两列,跟随者和跟随者中实现删除级联.
我的实际要求:
当从user_info表中删除任何记录时,该用户应基于ID列从关注表中删除,该ID可能存在于关注列或关注者列中.
我想从父表中删除任何与ID相关的父表时删除跟随表的所有记录.
Could not create constraint. See previous errors.
Note: But i want to implement on delete cascade in both columns, following and follower.
My actual requirement:
when any record is deleted from user_info table then that user should deleted from follow table based on ID column, that ID may be exist in following or follower column.
i want to delete all records of follow table when any id is related parent table is deleted from parent table
推荐答案
您可以设置表以允许Delete Cascade
.
在此处阅读更多信息 [
You can set your tables to allow aDelete Cascade
.
Read more about this here[^].
这篇关于在一个表中删除外键级联的倍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!