有2个用户A、B,现在在用户A下创建一个表: create table  test  as select * from B.test 
   如何使A用户下的test表也拥有B用户下的索引

解决方案 »

  1.   

    create table test as select * from B.test
    这样只能是把b表中的数据复制过来 连b表的主键都复制不了 
    你还是给a手动创建索引吧
      

  2.   

    使用联机重定义的功能SQL> create table r2mp.test(id number primary key);Table createdSQL> select index_name from all_indexes where table_name ='TEST' and owner='R2MP';INDEX_NAME
    ------------------------------
    SYS_C00182166SQL> create table R2MP.t_test as select * from r2mp.test;Table createdSQL> select index_name from all_indexes where table_name ='T_TEST'and owner='R2MP';INDEX_NAME
    ------------------------------SQL> execute dbms_redefinition.can_redef_table('R2MP','TEST');PL/SQL procedure successfully completedSQL> select * from v$version;BANNER
    ----------------------------------------------------------------
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE 9.2.0.1.0 ProductionTNS for HPUX: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - ProductionSQL> execute dbms_redefinition.start_redef_table('R2MP','TEST','T_TEST');PL/SQL procedure successfully completedSQL> execute dbms_redefinition.finish_redef_table('R2MP','TEST','T_TEST');PL/SQL procedure successfully completedSQL> select index_name from all_indexes where table_name ='T_TEST'and owner='R2MP';INDEX_NAME
    ------------------------------
    SYS_C00182166SQL>