Oracle 数据库,将唯一索引转换为非唯一索引

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

Oracle database, converting unique index to non-unique one

oracle

提问by Haozhun

I understand I can't do this straightforward from studying similar questions on stackoverflow and other sites.

我知道我无法通过研究 stackoverflow 和其他网站上的类似问题直接做到这一点。

However, I need to do this and I'm willing to go with workarounds.

但是,我需要这样做并且我愿意采用变通方法。

I tried to create a non-unique index with onlineand parallel, and then drop the old unique index. However, it fails saying ORA-01408: such column list already indexed.

我尝试使用onlineand创建非唯一索引parallel,然后删除旧的唯一索引。但是,它没有说ORA-01408: such column list already indexed

How to convert an unique index to a non-unique one?

如何将唯一索引转换为非唯一索引?

回答by Jeffrey Kemp

If you don't want to drop the old index before creating the new one, you can cheat a bit by creating the new index with an additional useless column, e.g.:

如果您不想在创建新索引之前删除旧索引,您可以通过使用额外的无用列创建新索引来作弊,例如:

Assuming a table with the following configuration:

假设一个表具有以下配置:

create table mytable (id number);

create unique index myunique on mytable (id);

To convert the index to non unique:

要将索引转换为非唯一:

create index temp on mytable (id, 1);

drop index myunique;

create index mynonunique on mytable (id);

drop index temp;

In practice I'm not sure how necessary this is - generally I'd just drop and recreate the index in some low-activity period, preferably take the application down.

在实践中,我不确定这有多必要 - 通常我只会在某个低活动期删除并重新创建索引,最好关闭应用程序。