ITPub博客

首页 > 数据库 > Oracle > 移动表move tablespace

移动表move tablespace

原创 Oracle 作者:pxbibm 时间:2014-05-22 22:41:02 0 删除 编辑

当我们建立表时,把表建立错了,或者把表建立到系统表空间了,或者不是自己默认用户下的表空间,我们需要使用
移动表的技术,把表移动到自己用户下的表空间。
注意:在移动了表,索引也需要手动移动。
实验如下;

SQL> create tablespace ts_test datafile 'D:\oracle\oradata\devdb\test01.dbf' size 10m;

表空间已创建。

SQL> create table test(id number,name varchar2(10));

表已创建。
SQL> create index ti_id on  test(id);

索引已创建。

SQL> select index_name,status,tablespace_name from user_indexes where index_name='TI_ID';

INDEX_NAME           STATUS           TABLESPACE_NAME
-------------------- ---------------- --------------------
TI_ID                VALID            USERS

SQL> select table_name,tablespace_name from user_tables where table_name='TEST';

TABLE_NAME           TABLESPACE_NAME
-------------------- --------------------
TEST                 USERS


SQL> insert into test values(1,'pxboracle');

已创建 1 行。

SQL> commit;

提交完成。


SQL> alter table test move tablespace ts_test;

表已更改。

SQL> select table_name,tablespace_name from user_tables where table_name='TEST';

TABLE_NAME           TABLESPACE_NAME
-------------------- --------------------
TEST                 TS_TEST

SQL>  select index_name,status,tablespace_name from user_indexes where index_name='TI_ID';

INDEX_NAME           STATUS           TABLESPACE_NAME
-------------------- ---------------- --------------------
TI_ID                UNUSABLE         USERS

SQL> alter index ti_id rebuild tablespace ts_test;

索引已更改。

SQL> select index_name,status,tablespace_name from user_indexes where index_name='TI_ID';

INDEX_NAME           STATUS           TABLESPACE_NAME
-------------------- ---------------- --------------------
TI_ID                VALID            TS_TEST


-----------------------------------------------------------------------------------------------------------------------
pxboracle@live.com
2014.5.22 22:40
share you knowledge with the world.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12798004/viewspace-1167952/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 优化全表扫描
请登录后发表评论 登录
全部评论
【DBAplus社群】联合发起人。ACOUG核心成员,Oracle用户组年轻专家。熟悉Oracle的体系结构,擅长Oracle数据库架构规划、SQL优化、OWI方面性能的优化。曾服务于航天、航空、机车、大型制造行业数据库的维护以及系统开发工作,开发过基于Oracle数据库的大型ERP系统。
  • 博文量
    341
  • 访问量
    2469605