Script to Move Tables and Indexes to another Tablespace

Generating a Script to move all tables to another tablespace in a schema: -

set heading off
set pages 0
set feedback off
spool move_tables.sql
SELECT 'ALTER TABLE '|| OWNER ||'.'|| OBJECT_NAME ||' MOVE TABLESPACE '||' USERS ;'
FROM ALL_OBJECTS WHERE OWNER = 'SCOTT' AND OBJECT_TYPE = 'TABLE'
/
spool off
@move_tables.sql

Generating a Script to rebuild all indexes to another tablespace in a schema: -

set heading off
set pages 0
set feedback off
spool move_indexes.sql
SELECT 'ALTER INDEX '|| OWNER ||'.'||INDEX_NAME||' REBUILD TABLESPACE USERS ;' FROM ALL_INDEXES
WHERE OWNER = 'LEAD'
/
spool off
@move_indexes.sql

No comments:

Post a Comment