sql - Adding data to existing table with primary key violates unique constraint despite being unique?
问题描述
I am attempting to add new data to the database I have created, however, I keep getting an error "ORA-00001" when adding to the table despite the data within the PK column being unique.
How am I able to add new data to the primary column, or do constraints need to be disabled every time?
I was attempting to do so via:
UPDATE Specialists
SET Specialist_ID = 210000000005,
First_Name = 'Aaron',
Last_Name = 'Black',
Specialist_Category = 'Software',
Cases_In_Progress = 0;
I have Googled as specifically as I can to narrow down search results but I haven't been able to find the answer to just add new data into the PK column of an existing table.
Much appreciated!
解决方案
您的代码显然违反了primary key
约束。这是出于以下两个原因之一:
- 已经有一行主键具有您为其分配的值。
- 您的更新更新不止一行。
我会选择后者。
假设这Specialist_ID
是主键,您可能打算
UPDATE Specialists
SET First_Name = 'Aaron',
Last_Name = 'Black',
Specialist_Category = 'Software',
Cases_In_Progress = 0
WHERE Specialist_ID = 210000000005;
在任何情况下,UPDATE
没有WHERE
子句的简单语句都是可疑的,因为它会更新表中的所有行。
推荐阅读
- docker - Play 应用的 Docker 化
- python - 使用文件中的 matplotlib 绘制动画
- prolog - When does Prolog prompts 'yes' and when does it says 'true'
- javascript - 用于 CORS 的 Vue.js 代理无法正常运行
- typescript - 如何在 AWS Cognito 用户电子邮件中允许变音符号?
- javascript - 在 React Native 中构建一个完全自定义的地图?
- python - 将嵌套的 JSON 放入 Pandas 数据框和 CSV
- foreach - ForEach 不适用于 Identifiable & id = UUID()
- php - 无法在远程服务器上运行 composer 命令
- python - Squarify — 如何调整树形图矩形形状