如何修复我的唯一约束违规问题 [英] How do I fix my unique constraint violation problem

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

问题描述

我创建了这个表,在尝试将值插入表中时,我不断收到此错误

I have created this table and upon trying to insert values into the table I keep getting this error

CREATE TABLE Jobs
(
        job_id numeric(5) NOT NULL,
        job_title varchar2(20) NOT NULL,
        PRIMARY KEY (job_id)
);

ORA-00001: unique constraint (SYS_C00721767) violated

任何人都可以告诉我我做错了什么并指导我正确的方向

谢谢



我尝试了什么:



我试图找出违规行为的位置(如下图所示)不幸的是我还没有幸运的是,我的意思是Oracle没有向我显示任何内容

Can anyone tell me what i am doing wrong and guide me in the right direction
Thanks

What I have tried:

I have tried to find out where the violation is (as shown below) unfortunately I have not had any luck by that I mean Oracle is not showing me anything

SELECT DISTINCT Jobs
FROM all_indexes
WHERE index_name = 'SYS_C00721767';

推荐答案

某处你正在尝试插入 job_id 已经存在的行。

在添加新行之前,您应该检查它是否已经存在
Somewhere you are attempting to insert a row where job_id already exists.
Before adding a new row you should check that it doesn't already exist with
SELECT job_title FROM Jobs WHERE job_id = @newid

其中 @newid 是你正在尝试的job_id插入。

或者,将job_id设为自动创建的增量字段,问题就会消失 - 请参阅 ORACLE-BASE - Oracle Database 12c第1版(12.1)中的标识列 [ ^ ]

where @newid is the job_id you are trying to insert.
Alternatively, make job_id an automatically created increment field and the problem will go away - see ORACLE-BASE - Identity Columns in Oracle Database 12c Release 1 (12.1)[^]


这篇关于如何修复我的唯一约束违规问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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