oracle 插入时Oracle唯一约束错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5203873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle unique constraint error when inserting
提问by nakiya
INSERT INTO SS_ALERT_EVENTS ( ALERT_ID, EVENT_ID, TIME_DURATION, ALERT_EVENT_EFFECT, DATASET_ASSIGN_RULE, KEY_FIELDS_ASSIGN_RULE, SIDE, ALERT_VALIDATION_RULE, UNIQUE_ID ) VALUES ( 'test1', 7 , 0, 1 , NULL, '5b414c4552545f494e535452554d454e542e496e737472756d656e742049445d203a3d205b54524144455f5245504f52542e496e737472756d656e742049445d3b', -1, '5b414c4552542e416374696f6e5d203a3d20313b', 1)
*
ERROR at line 1:
ORA-00001: unique constraint (ESV31SURV.PK_SS_ALERT_EVENTS) violated
The EVENT_ID field is the problem. But I want to insert it anyway. However, when I try to drop the constraint of that name, it says there is no such constraint. Further, no such constraint is shown in USER_CONSTRAINTS table. What should I do?
EVENT_ID 字段是问题所在。但无论如何我都想插入它。但是,当我尝试删除该名称的约束时,它说没有这样的约束。此外,USER_CONSTRAINTS 表中未显示此类约束。我该怎么办?
回答by a_horse_with_no_name
The unique constraint might be in fact be a primary key constraint - at least that's what the name suggests.
唯一约束实际上可能是一个主键约束 - 至少它的名字暗示了这一点。
Dropping the primary key of a table will potentially have very bad side effect it might break applications that rely on this primary key (and you will also have to drop all foreign keys that reference that table before you can drop the primary key)
删除表的主键可能会产生非常糟糕的副作用,它可能会破坏依赖此主键的应用程序(在删除主键之前,您还必须删除所有引用该表的外键)
That primary key was created with a purposes, so before blindly dropping it you should consult whoever created that schema and make sure that primary key is not needed (or should be redefined).
该主键是有目的的,因此在盲目删除它之前,您应该咨询创建该架构的人,并确保不需要(或应该重新定义)主键。
Having said all this: try to drop the PK using
说了这么多:尝试使用
ALTER TABLE SS_ALERT_EVENTS DROP PRIMARY KEY
But please double check if this is really a wise decision!
但请仔细检查这是否真的是一个明智的决定!