05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

602<br />

CHAPTER 13 ■ PARTITIONING<br />

7 SAL NUMBER(7,2),<br />

8 COMM NUMBER(7,2),<br />

9 DEPTNO NUMBER(2) NOT NULL,<br />

10 LOC VARCHAR2(13) NOT NULL<br />

11 )<br />

12 partition by range(loc)<br />

13 (<br />

14 partition p1 values less than('C') tablespace p1,<br />

15 partition p2 values less than('D') tablespace p2,<br />

16 partition p3 values less than('N') tablespace p3,<br />

17 partition p4 values less than('Z') tablespace p4<br />

18 )<br />

19 /<br />

Table created.<br />

We alter the table to add a constraint on the primary key column:<br />

ops$tkyte@ORA10G> alter table emp add constraint emp_pk<br />

2 primary key(empno)<br />

3 /<br />

Table altered.<br />

A side effect of this is that there exists a unique index on the EMPNO column. This shows we<br />

can support <strong>and</strong> enforce data integrity, one of our goals. Finally, we create two more global<br />

indexes on DEPTNO <strong>and</strong> JOB, to facilitate accessing records quickly by those attributes:<br />

ops$tkyte@ORA10G> create index emp_job_idx on emp(job)<br />

2 GLOBAL<br />

3 /<br />

Index created.<br />

ops$tkyte@ORA10G> create index emp_dept_idx on emp(deptno)<br />

2 GLOBAL<br />

3 /<br />

Index created.<br />

ops$tkyte@ORA10G> insert into emp<br />

2 select e.*, d.loc<br />

3 from scott.emp e, scott.dept d<br />

4 where e.deptno = d.deptno<br />

5 /<br />

14 rows created.<br />

Now let’s see what is in each partition:<br />

ops$tkyte@ORA10G> break on pname skip 1<br />

ops$tkyte@ORA10G> select 'p1' pname, empno, job, loc from emp partition(p1)<br />

2 union all<br />

3 select 'p2' pname, empno, job, loc from emp partition(p2)<br />

4 union all

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!