oracle 将非唯一索引更改为唯一索引

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

Alter a nonunique index to a unique index

oracleoracle10gconstraintsunique-constraint

提问by jworrin

I have a few non-unique constraints that I want to alter into unique constraints ( business rules have changed since the data model was made ). Is there any way to do it with out dropping and recreating as a unique constraint? I was thinking there would be an option in the alter constraintcommand, but I have not found anything.

我有一些非唯一约束,我想将其更改为唯一约束(自创建数据模型以来,业务规则已更改)。有什么办法可以不用删除和重新创建作为唯一约束吗?我在想alter constraint命令中会有一个选项,但我没有找到任何东西。

Thanks!!

谢谢!!

采纳答案by John Doyle

You can't modify a constraint in the way you wish you can only drop and recreate it. If you want to do this with no downtime then look into the DBMS_REDEFINITIONpackage.

您不能以您希望的方式修改约束,只能删除并重新创建它。如果您想在不停机的情况下执行此操作,请查看DBMS_REDEFINITION包。

回答by Jon Heller

You cannot convert a non-unique index into a unique index.

您不能将非唯一索引转换为唯一索引。

(It's difficult to say what cannot be done. I'm basing this answer on looking at the ALTER INDEXpage of the SQL Language Reference, searching for the word UNIQUE, and not finding any relevant hints. I looked at 11g instead of 10g, but that's probably better in this case because there are a few features that exist in 10g but are only documented in 11g.)

(很难说什么不能做。我的答案基于查看SQL 语言参考的ALTER INDEX页面,搜索单词 UNIQUE,但没有找到任何相关提示。我查看了 11g 而不是 10g,但在这种情况下这可能会更好,因为 10g 中存在一些功能,但仅在 11g 中记录。)

However, you can use a non-unique index for a unique constraint. But there are some performance considerations: a unique index would be smaller and faster.

但是,您可以对唯一约束使用非唯一索引。但是有一些性能方面的考虑:唯一索引会更小更快。

create table my_table(a number);

create index my_table_index on my_table(a);

alter table my_table add constraint my_table_unique unique (a)
    using index my_table_index;

回答by zquanghoangz

In my case, just do drop and re-create the index:

就我而言,只需删除并重新创建索引:

DROP INDEX index_name;
CREATE UNIQUE INDEX index_name ON table_name (col01,col02) TABLESPACE indx;