注册
达梦数据库-错误码-[-6607]-分析处理
专栏/技术分享/ 文章详情 /

达梦数据库-错误码-[-6607]-分析处理

PYZ 2024/06/14 1183 1 0
摘要

错误码:-6607
错误内容:违反引用约束[%s]

原因:

创建外键时子表里存在父表不存在的数据

示例:

--创建父表 create table test1(id int,name varchar(20),constraint pk_test1_id primary key(id)); insert into test1 values(1,'A'); insert into test1 values(2,'B'); commit; --创建子表 create table test2(id int,name varchar(20)); insert into test2 values(1,'A'); insert into test2 values(3,'C'); commit; --执行添加外键 alter table test2 add constraint fk_test2_id foreign key(id) references test1(id); -6607: 违反引用约束[FK_TEST2_ID]

问题处理:

1、查询子表中存在,且父表中不存在的数据;

select * from test2 where not exists (select 1 from test1 where test1.id=test2.id);

2、删除子表数据,或在父表中新增数据;

评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服