DROP TABLE t1 PURGE; -- Create table. CREATE TABLE t1 AS SELECT level AS id, ‘Description for ‘ || level AS description, SYSDATE AS created_date FROM dual CONNECT BY level <= 1000; COMMIT; ALTER TABLE t1 ADD CONSTRAINT t1_pk PRIMARY KEY (id); CREATE INDEX t1_created_date_idx ON t1(created_date);
在以前的版本中,移动表是脱机操作,默认情况下,标记索引为不可用。
-- Offline: Basic move. ALTER TABLE t1 MOVE TABLESPACE users; -- Check indexes. SELECT index_name, status FROM user_indexes ORDER BY 1; INDEX_NAME STATUS ------------------------------ -------- T1_CREATED_DATE_IDX UNUSABLE T1_PK UNUSABLE 2 rows selected. SQL>
我们可以手动重新生成索引。
-- Manually rebuild indexes. ALTER INDEX t1_pk REBUILD ONLINE; ALTER INDEX t1_created_date_idx REBUILD ONLINE; -- Check indexes. SELECT index_name, status FROM user_indexes ORDER BY 1; INDEX_NAME STATUS ------------------------------ -------- T1_CREATED_DATE_IDX VALID T1_PK VALID 2 rows selected. SQL>
或者,我们可以包括子句来管理我们的索引。UPDATE INDEXES
-- Offline: Include UPDATE INDEXES to manage the indexes. ALTER TABLE t1 MOVE TABLESPACE users UPDATE INDEXES; -- Check indexes. SELECT index_name, status FROM user_indexes ORDER BY 1; INDEX_NAME STATUS ------------------------------ -------- T1_CREATED_DATE_IDX VALID T1_PK VALID 2 rows selected. SQL>
From Oracle 12.2 onward we can move the table as an online operation using the keyword. In addition to moving the table, the online move automatically maintains the indexes.ONLINE
-- Online: Basic move. ALTER TABLE t1 MOVE ONLINE TABLESPACE users; -- Check indexes. SELECT index_name, status FROM user_indexes ORDER BY 1; INDEX_NAME STATUS ------------------------------ -------- T1_CREATED_DATE_IDX VALID T1_PK VALID 2 rows selected. SQL>
我们还可以使用此功能在联机操作中更改表压缩和存储参数。
-- Online: Change table compression. ALTER TABLE t1 MOVE ONLINE TABLESPACE users COMPRESS; ALTER TABLE t1 MOVE ONLINE TABLESPACE users NOCOMPRESS; -- Online: Change storage parameters. ALTER TABLE t1 MOVE ONLINE STORAGE (PCTINCREASE 0);
oracle 12.2 alter table move online
原文:https://www.cnblogs.com/nadian-li/p/13705877.html