gpt4 book ai didi

mysql - 有人可以解释为什么我在 sql 查询中遇到此错误

转载 作者:行者123 更新时间:2023-11-29 22:46:05 24 4
gpt4 key购买 nike

create table Department (
Dep_ID int not null,
Dep_Name varchar(30),
primary key (Dep_ID),
)

create table Course (
C_ID int not null,
C_Name varchar (30) not null,
C_Duration varchar (10) not null,
DegreeType varchar (20),
Dep_ID int,
primary key (C_ID),
constraint DEP_ID1 foreign key (Dep_ID) references Department (Dep_ID) on update cascade,
)


create table Student (
St_ID int not null,
St_Name varchar (100),
St_age smallint,
St_gender Varchar(6),
St_tel int,
St_ADD varchar (100) not null,
St_city varchar (50)not null,
St_type varchar (20) not null,
St_nationality varchar (5) not null,
Dep_ID int,
C_ID int,
primary key (St_ID),
constraint DEP_ID foreign key (Dep_ID) references Department(Dep_ID) on update cascade,
constraint CO_ID foreign key (C_ID) references Course(C_ID) on update cascade,

)

create table Staff (
Sta_ID int not null,
Sta_Name varchar (100) not null,
Sta_type varchar (20) not null,
Sta_Add varchar (100) not null,
Sta_tel int ,
Dep_ID int,
primary key (Sta_ID),
constraint DEeP_ID foreign key (Dep_ID) references Department (Dep_ID) on update cascade,
)

this is the error im getting why cant i use cascade update on composite keys

消息 1785,级别 16,状态 0,第 19 行在表“Student”上引入外键约束“CO_ID”可能会导致循环或多个级联路径。指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。消息 1750,级别 16,状态 0,第 19 行无法创建约束。查看以前的错误。

最佳答案

我做了一项研究,发现这个问题可以通过更改行来解决: constraint CO_ID foreign key (C_ID) references Course(C_ID) on update cascade,constraint CO_ID foreign key (C_ID) references Course(C_ID) on update No Action,

我在以下链接中得到了解释: Foreign key constraint may cause cycles or multiple cascade paths?

这可能会解决您的问题。

关于mysql - 有人可以解释为什么我在 sql 查询中遇到此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29117826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com