暂无图片
删除索引报错ORA-02429
我来答
分享
暂无图片 匿名用户
删除索引报错ORA-02429

删除索引报错ORA-02429: cannot drop index used for enforcement of unique /primary key,但是该索引感觉不是唯一约束创建的索引,请大师指点一下



我来答
添加附件
收藏
分享
问题补充
3条回答
默认
最新
lnn

列上约束是主键/唯一吧,创建该约束会自动创建索引,删除约束便会自动删除索引

暂无图片 评论
暂无图片 有用 0
冯睿

还是先确认一下这个索引是否为主键约束创建的唯一索引吧,从报错来看,大概率是这个问题。

查一下该表的这个列上的索引情况。

select INDEX_NAME,TABLE_NAME,COLUMN_NAME from dba_ind_columns where table_name='CODEDATADE';

暂无图片 评论
暂无图片 有用 0
Thomas

其实做个试验,就很清楚了:

--Create table and populate data:
create table tb_zxp (id integer, cc varchar2(10));
insert into tb_zxp select level, 'abc'||mod(level,50) from dual connect by level <1001;
commit;

--Create a normal index named idx1 referencing id and cc columns:
create index idx1 on tb_zxp (id,cc);

--Create unique constraint on the table:
alter table tb_zxp add constraint u_id unique (id);

--Query corresponding index_name of the constraint. Definitely, Oracle automatically established the relationship between index IDX1 and constraint U_ID:
SQL> select index_name from user_constraints where constraint_name='U_ID';

INDEX_NAME
------------------------------------------------------------------
IDX1

--So, if you drop IDX1, Oracle will show error:
SQL> drop index idx1;
drop index idx1
*
ERROR at line 1:
ORA-02429: cannot drop index used for enforcement of unique/primary key

--Now we create another unique index named IDX2 on id column:
SQL> create unique index idx2 on tb_Zxp(id);

Index created.

--And, we modify the constraint with its corresponding index being referenced to IDX2:
SQL> alter table tb_zxp modify constraint u_id using index idx2;

Table altered.

--Finally, we can drop IDX1 successfully:

SQL> select index_name from user_constraints where constraint_name='U_ID';

SQL> drop index idx1;

Index dropped.

暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏