如何以索引组织方式重新创建表?

时间:2011-04-13 15:37:09

标签: sql oracle oracle10g

在Oracle 10g数据库中,我想重新创建一个表(保持其所有数据)作为索引组织。最简单的方法是什么?

1 个答案:

答案 0 :(得分:3)

RENAME EXISTING_TABLE TO OLD_HEAP_TABLE;

CREATE TABLE NEW_IOT_TABLE AS
 ([COLUMNS FROM EXISTING TABLE]
  CONSTRAINT NEW_IOT_TABLE_PK PRIMARY KEY ([PK_COLUMNS FROM EXISTING TABLE]
 )
 ORGANIZATION INDEX;


INSERT INTO NEW_IOT_TABLE
SELECT * FROM OLD_HEAP_TABLE;

COMMIT;

RENAME NEW_IOT_TABLE TO EXISTING_TABLE;

-- DROP OLD_HEAP_TABLE when you're sure it all worked.