如何使用简单的命令将表及其索引移动至另一个表空间? (DBMR2363)
从DBMaster5.3开始,DBMaster支持命令 “ALTER TABLE table_name MOVE TABLESPACE tablespace_name”,该命令用于将表及其索引移动至另一个表空间。移动对象的进程完成前,用户不能访问该表的数据。
- 如果表及其索引位于相同的表空间,用户能够使用命令同时将其移动至另一个表空间;此外,通过重建索引,将索引和表移动至不同的表空间。
例如:
在表空间ts1创建表t1及其索引idx1,首先通过使用命令“alter table t1 move tablespace ts2”,将表及其索引移动至表空间ts2 ,接着通过重建索引,将索引idx1移动至表空间ts3 。详情如下所示:
dmSQL> create table t1(c1 int,c2 int) in ts1;
dmSQL> create index idx1 on (c1) in ts1;
dmSQL> def table t1;
create table SYSADM.T1 (C1 INTEGER default null, C2 INTEGER default null) in TS1 lock mode row fillfactor 100;
create index IDX1 on SYSADM.T1 (C1 asc) in TS1;
dmSQL> alter table t1 move tablespace ts2;
dmSQL> def table t1;
create table SYSADM.T1 (C1 INTEGER default null , C2 INTEGER default null) in TS2 lock mode row fillfactor 100 ;
create index IDX1 on SYSADM.T1 ( C1 asc ) in TS2;
dmSQL> rebuild index idx1 for t1 in ts3;
dmSQL> def table t1;
create table SYSADM.T1 (C1 INTEGER default null , C2 INTEGER default null) in TS2 lock mode row fillfactor 100 ;
create index IDX1 on SYSADM.T1 (C1 asc) in TS3;
- 如果表及其索引位于不同的表空间,用户首先能将表移动至不同的表空间,接着通过重建索引,将索引移动至表空间。
例如:
首先在表空间ts1创建表t3,在表空间ts2创建其索引idx3,接着使用命令“alter table t3 move tablespace ts3”,将表t3移动至表空间ts3 ,最后通过重建索引,将索引idx1移动至表空间ts3 。详情如下所示:
dmSQL> create table t3(c1 int,c2 int) in ts1;
dmSQL> create index idx3 on t3(c1) in ts2;
dmSQL> def table t3;
create table SYSADM.T3 (C1 INTEGER default null , C2 INTEGER default null) in TS1 lock mode row fillfactor 100 ;
create index IDX3 on SYSADM.T3 (C1 asc) in TS2;
dmSQL> alter table t3 move tablespace ts3;
dmSQL> def table t3;
create table SYSADM.T3 (C1 INTEGER default null , C2 INTEGER default null) in TS3 lock mode row fillfactor 100;
create index IDX3 on SYSADM.T3 (C1 asc) in TS2;
dmSQL> rebuild index idx3 for t3 in ts3;
dmSQL> def table t3;
create table SYSADM.T3 (C1 INTEGER default null , C2 INTEGER default null)in TS3 lock mode row fillfactor 100;
create index IDX3 on SYSADM.T3 (C1 asc) in TS3;
在DBMaster5.3之前,用户能根据以下步骤将表及其索引移动至另一个表空间。
- 将表导出至一个外部文本文件。.
UNLOAD TABLE FROM table_name TO file_name
2. 打开文本文件“file_name”, 手动修改表空间的名称。
alter table SYSADM.TEST primary key (C1) in old_TS1;
==> alter table SYSADM.TEST primary key (C1) in new_TS1;
create index intest_SYSADM.TEST on SYSADM.TEST (C2 asc, C3 asc) in old_TS1
==> create index intest_SYSADM.TEST on SYSADM.TEST (C2 asc, C3 asc) in new_TS1
3. 删除表 “table_name”,然后从文本文件“file_name”导入表的内容。
LOAD TABLE FROM file_name
版本: DBMaster 4.x/5.x
产品: Normal/Bundle
平台: Windows/Linux