首页 > 代码库 > 模拟行迁移试验

模拟行迁移试验

1、创建scott模式

[oracle@std dbs]$ sqlplus /as sysdbaSQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 17 14:59:02 2014Copyright (c) 1982, 2005, Oracle.  All rights reserved.Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsSQL> select user_id,username from dba_users;   USER_ID USERNAME---------- ------------------------------    11 OUTLN     0 SYS     5 SYSTEM    24 DBSNMP    21 TSMSYS    19 DIP6 rows selected.SQL> @?/rdbms/admin/utlsampl.sqlDisconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining options

 

2、备份EMP表

[oracle@std dbs]$ sqlplus scott/tigerSQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 17 15:02:50 2014Copyright (c) 1982, 2005, Oracle.  All rights reserved.Error accessing PRODUCT_USER_PROFILEWarning:  Product user profile information not loaded!You may need to run PUPBLD.SQL as SYSTEMConnected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsSQL> select * from tab;TNAME                   TABTYPE    CLUSTERID------------------------------ ------- ----------DEPT                   TABLEEMP                   TABLEBONUS                   TABLESALGRADE               TABLESQL> select constraint_name,constraint_type,table_name from user_constraints;CONSTRAINT_NAME            C TABLE_NAME------------------------------ - ------------------------------FK_DEPTNO               R EMPPK_DEPT                P DEPTPK_EMP                   P EMPSQL> alter table emp drop constraints pk_emp;Table altered.

 

3、分析行连接

SQL> @?/rdbms/admin/utlchain.sqlTable created.SQL> select * from tab;TNAME                   TABTYPE    CLUSTERID------------------------------ ------- ----------DEPT                   TABLEEMP                   TABLECHAINED_ROWS               TABLEBONUS                   TABLESALGRADE               TABLEEMP2                   TABLE6 rows selected.SQL> analyze table emp list chained rows into chained_rows;Table analyzed.SQL> select count(*) from chained_rows where table_name=EMP;  COUNT(*)----------     0

4、模拟产生行连接

SQL> truncate table emp;Table truncated.SQL> alter table emp pctfree 0;Table altered.SQL> insert into emp select * from emp2;14 rows created.SQL> insert into emp select * from emp;14 rows created.SQL> /28 rows created.SQL> /56 rows created.SQL> /112 rows created.SQL> /224 rows created.SQL> /448 rows created.SQL> /896 rows created.SQL> /1792 rows created.SQL> commit;Commit complete.SQL> desc emp Name                       Null?    Type ----------------------------------------- -------- ---------------------------- EMPNO                            NUMBER(4) ENAME                            VARCHAR2(10) JOB                            VARCHAR2(9) MGR                            NUMBER(4) HIREDATE                        DATE SAL                            NUMBER(7,2) COMM                            NUMBER(7,2) DEPTNO                         NUMBER(2)SQL> update emp set ename=AAAAAAAAAA where empno=7844;256 rows updated.SQL> commit;Commit complete.SQL> analyze table emp list chained rows into chained_rows;Table analyzed.SQL> select count(*) from chained_rows where table_name=EMP;  COUNT(*)----------    30

5、消除行迁移

SQL> create table emp_old as select * from emp where rowid in  2  (select head_rowid from chained_rows  3  where table_name=EMP);Table created.SQL> delete from emp where rowid in   2  (select head_rowid from chained_rows  3  where table_name=EMP);30 rows deleted.SQL> insert into emp select * from emp_old;30 rows created.SQL> drop table emp_old;Table dropped.SQL> delete from chained_rows where table_name=EMP;30 rows deleted.SQL> commit;Commit complete.SQL> analyze table emp list chained rows into chained_rows;Table analyzed.SQL> select count(*) from chained_rows where table_name=EMP;  COUNT(*)----------     0

 

模拟行迁移试验