关于删除级联约束 [英] on delete cascade constraint

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

问题描述

我在创建删除级联约束时遇到了一些困难.

我有3张桌子-可以说table1,table2& table3
table1具有主键"key1"
table2具有主键"key2"&具有on删除级联约束的foriegn键"key1"参考表1.
现在,当我尝试使用外键创建一个table3时-"key1"& "key2"是指表"table1"& "table2"分别在两个表上都具有on delete级联约束.

它给出了此错误-

hi i''m having some difficulties in creating on delete cascade constraint.

i have 3 tables- lets say table1, table2 & table3
table1 has a primary key "key1"
table2 has a primary key "key2" & a foriegn key "key1" reference table1 with on delete cascade constraint.
now when i try to create a table3 with foreign keys- "key1" & "key2" referred to tables "table1" & "table2" respectively with on delete cascade constraint on both...

it gives this error-

Introducing FOREIGN KEY constraint ''FK__table3__key2__1D114BD1'' on table ''table3'' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.



这就是我的做法...
我的代码:



this is how i''m doing it...
My code:

create table table1
(
key1 varchar(20) primary key
)
create table table2
(
key2 integer identity primary key,
key1 varchar(20) references table1 on delete cascade
)
create table table3
(
key1 varchar(20) references table1 on delete cascade,
key2 integer references table2 on delete cascade
)



请提出一些我需要对全部删除级联约束应用的内容.



please suggest something i need to apply on delete cascade constraint on all.

推荐答案

您好朋友使用此语法而不是您的语法,它将与您的删除级联条件一起使用

hello friend use this syntax instead of yours it will work fine with your on-delete cascade criteria

create table table1
(
key1 varchar(20) primary key
)


create table table2
(
key2 integer identity primary key,
key1 varchar(20) references table1 on delete cascade
)


create table table3
(
key1 varchar(20) references table1,
key2 integer references table2 on delete cascade
)


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

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