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


列上约束是主键/唯一吧,创建该约束会自动创建索引,删除约束便会自动删除索引
评论
有用 0还是先确认一下这个索引是否为主键约束创建的唯一索引吧,从报错来看,大概率是这个问题。
查一下该表的这个列上的索引情况。
select INDEX_NAME,TABLE_NAME,COLUMN_NAME from dba_ind_columns where table_name='CODEDATADE';
评论
有用 0其实做个试验,就很清楚了:
--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
墨值悬赏

