oracle 更新主键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4469506/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:13:52  来源:igfitidea点击:

update primary key in oracle

oracleprimary-key

提问by Mohamed Saligh

i have table. which has 5 columns in that 3 of the columns makes primary key combinations.

我有桌子。其中有 5 列,其中 3 列构成主键组合。

table (cola, colb, colc, cold, cole)

表(可乐,colb,colc,cold,cole)

i want to update one of the column which is in primary key group. how to do that?

我想更新主键组中的列之一。怎么做?

its giving primary key constraint error.

它给出了主键约束错误。

回答by Spredzy

You should disable do your modification an re enable the constraints that are linked to your primary key. (Unique, non-null, etc...)

您应该禁用修改并重新启用链接到主键的约束。(唯一的,非空的,等等...)

Take a look at this website

看看这个网站

回答by davek

If you really need to maintain uniqueness over these three columns, then define a unique constraint on the three columns making up your current PK, and then define a new surrogate primary key column.

如果你真的需要保持这三列的唯一性,那么在构成你当前 PK 的三列上定义一个唯一约束,然后定义一个新的代理主键列。

回答by bernd_k

Just in case you have to change the referncing data too. First note contrary to MS-SQL-Server there is no foreign Key contraint with on update cascade see How to create a Foreign Key with “ON UPDATE CASCADE” on Oracle?.

以防万一您也必须更改引用数据。第一个注意事项与 MS-SQL-Server 相反,更新级联没有外键约束,请参阅如何在 Oracle 上使用“ON UPDATE CASCADE”创建外键?.

Than I would insert a new row in the primary table, update the referencing table to reference the new row and finally delete the original primary row.

我会在主表中插入一个新行,更新引用表以引用新行,最后删除原始主行。