暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 将唯一索引转换为非唯一索引

ASKTOM 2020-04-09
1479

问题描述

嗨,汤姆!

前段时间,我决定将我的唯一索引更改为非唯一索引,因为有新的要求。我谷歌了很多,但没有找到任何关于convertation
Though I found solutions like creating new nnon-unique index with extra constant field in it and then deleting unique index or just drop-create solution。
但是我想知道为什么没有选择将唯一索引更改为非唯一索引?是否有一些内部存储的东西在唯一索引和非唯一索引之间是不同的?

专家解答

没有办法将非唯一索引更改为唯一索引。

请记住,唯一索引是约束的一种形式。您是说列列表中的每组值只能有一行。

在一般情况下,这要求您在应用约束之前使用清理数据。

从12c可以在同一列列表中创建许多索引。提供:

-具有不同的属性 (唯一性,分区,位图与btree,...)
-只有一个是可见的

所以你可以交换一个非唯一和唯一的索引做这样的事情:

create table t (
  c1 int
);

create index i 
  on t ( c1 );
  
create unique index ui 
  on t ( c1 )
  invisible;
  
alter index i
  invisible;

alter index ui 
  visible;
复制


请注意,这意味着c1上没有可见索引的时间很短!交换索引时,您可能希望短暂中断。

唯一索引和非唯一索引之间也有一大堆细微的区别。理查德·富特 (Richard Foote) 从以下系列开始讨论这些问题:https://richardfoote.wordpress.com/2007/12/18/differences-between-unique-and-non-unique-indexes-part-i/
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论