set unused column和檢視,約束,同義詞和索引的關係

viadeazhu發表於2010-09-11

當使用alter table set unused column語法之後,會對其相關聯的檢視,約束,同義詞和索引有什麼作用麼?

答案是:

檢視和同義詞會失效,其中同義詞再次引用即可重新編譯,但是檢視重新編譯會報錯;

約束和索引會被自動刪除。

 

實驗:

SQL> create table test as select * from dba_objects;

Table created.

SQL> create view testview as select * from test;

View created.

SQL> alter table test add constraint testc check(object_id<999999); 

Table altered.

SQL> create index testidx on test(object_id);

Index created.

SQL> create synonym testsyn for test;

Synonym created.


SQL> select CONSTRAINT_NAME,status from user_constraints
  2  where CONSTRAINT_NAME in ('TESTC');

CONSTRAINT_NAME                STATUS
------------------------------ --------
TESTC                          ENABLED

SQL> select OBJECT_NAME,status from user_objects
  2  where OBJECT_NAME in ('TESTVIEW','TESTIDX','TESTSYN');

OBJECT_NAME                    STATUS
------------------------------ -------
TESTIDX                        VALID
TESTSYN                        VALID
TESTVIEW                       VALID

SQL> alter table test set unused (object_id);

Table altered.

SQL> select CONSTRAINT_NAME,status from user_constraints
  2  where CONSTRAINT_NAME in ('TESTC');               

no rows selected

SQL> select OBJECT_NAME,status from user_objects           
  2  where OBJECT_NAME in ('TESTVIEW','TESTIDX','TESTSYN');

OBJECT_NAME                    STATUS
------------------------------ -------
TESTSYN                        INVALID
TESTVIEW                       INVALID                      
                      

SQL> select count(*) from TESTSYN;

  COUNT(*)
----------
     10069

SQL> select count(*) from TESTVIEW;
select count(*) from TESTVIEW
                     *
ERROR at line 1:
ORA-04063: view "HAO.TESTVIEW" has errors
                       
                        
                      

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15415488/viewspace-673249/,如需轉載,請註明出處,否則將追究法律責任。

相關文章