原帖由 fish617 于 2008-7-16 18:27 發(fā)表
設置index為unusable時,要修改參數(shù)skip_unusable_indexes為TRUE,否則用到該索引時會報錯.
show parameter skip
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
skip_unusable_indexes boolean TRUE
alter index pk_test unusable
select index_name,status,table_name from user_indexes;
INDEX_NAME STATUS TABLE_NAME
------------------------------ -------- ------------------------------
PK_TEST UNUSABLE TEST
insert into test values(12,'asdf');
insert into test values(12,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable
state
SQL> create table test(id number,name varchar2(10));
Table created.
SQL> alter table test add constraint pk_test primary key(id);
Table altered.
SQL> select index_name,status from user_indexes;
INDEX_NAME STATUS
------------------------------ --------
PK_TEST VALID
SQL> select index_name,status from user_indexes;
INDEX_NAME STATUS
------------------------------ --------
PK_TEST VALID
SQL> insert into test values (1,'sdfs');
1 row created.
SQL> commit;
Commit complete.
SQL> alter index PK_TEST unusable;
Index altered.
SQL> select index_name,status from user_indexes;
INDEX_NAME STATUS
------------------------------ --------
PK_TEST UNUSABLE
SQL> insert into test values (2,'asdf');
insert into test values (2,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable state
SQL> drop table test purge;
Table dropped.
SQL> create table test(id number,name varchar2(10));
Table created.
SQL> create index pk_test on test(id);
Index created.
SQL> select index_name,status from user_indexes;
INDEX_NAME STATUS
------------------------------ --------
PK_TEST VALID
SQL> insert into test values (2,'asdf');
1 row created.
SQL> alter index PK_TEST unusable;
Index altered.
SQL> select index_name,status from user_indexes;
INDEX_NAME STATUS
------------------------------ --------
PK_TEST UNUSABLE
SQL> insert into test values (3,'dddffd');
1 row created
SQL> create table test(id number,name varchar2(10));
Table created.
SQL> alter table test add constraint pk_test unique (id);
Table altered.
SQL> select index_name,status from user_indexes;
INDEX_NAME STATUS
------------------------------ --------
PK_TEST VALID
SQL> insert into test values (1,'sdfs');
1 row created.
SQL> commit;
Commit complete.
SQL> alter index PK_TEST unusable;
Index altered.
SQL> select index_name,status from user_indexes;
INDEX_NAME STATUS
------------------------------ --------
PK_TEST UNUSABLE
SQL> insert into test values (2,'asdf');
insert into test values (2,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable
state
select CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME,STATUS from user_constraints;
CONSTRAINT_NAME C TABLE_NAME STATUS
------------------------------ - ------------------------------ --------
PK_TEST U TEST ENABLED
SQL> drop table test purge;
Table dropped.
SQL> create table test(id number,name varchar2(10));
Table created.
SQL> alter table test add constraint pk_test unique (id);
Table altered.
SQL> alter index PK_TEST unusable;
Index altered.
SQL> insert into test values (2,'asdf');
insert into test values (2,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable
state
SQL> alter table test disable constraint pk_test;
Table altered.
SQL> insert into test values (2,'asdf');
1 row created.
SQL> select CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME,STATUS from user_constraints;
CONSTRAINT_NAME C TABLE_NAME STATUS
------------------------------ - ------------------------------ --------
PK_TEST U TEST DISABLED
歡迎光臨 Chinaunix (http://www.72891.cn/) | Powered by Discuz! X3.2 |