Sie sind auf Seite 1von 5

Create normal/heap table:

Create table employee


(eno number(4), ename varchar2(20), address varchar2(30), deptno
number(10) ,
constraint emp_no_pk primary key (eno))
Tablespace tbs_dict
Storage(initial 1m next 1m minextents 1 maxextents 10 pctincrease 10
Freelists 1 freelist groups 2 buffer_pool default)
Pctfree 10
Pctused 40
Initrans 1
Maxtrans 10
Nologging
Nocache;

Add column

Alter table employee add phone number;

Drop column

Alter table employee drop column phone; (Cannot drop all the columns)

To enable or disable constraint

Alter table employee disable | enable constraint emp_no_pk;

Manually deallocate extents

Alter table employee deallocate unused;


Alter table employee deallocate unused keep 1m;

(deallocates other extents

keeping 1m)

To enable or disable constraint

Alter table employee disable | enable constraint emp_no_pk;

Move table to another tablespace

Alter table employee move tablespace newtbs


storage ( .. .. );

Views:
Dba_unused_col_tab
Dba_segments
Dba_extents
Dba_objects
Dba_tables

Partition tables:
Range partition:
Create table emp_part(empno number,ename varchar2(20) )
Partition by range (empno)
(partition part1 values less than (250)
tablespace tbs1 storage( .. .. ),
partition part2 values less than (500)
tablespace tbs2 storage( .. .. ),
partition part3 values less than (750)

tablespace tbs3 storage( .. .. ),


partition part4 values less than (MAXVALUE)
tablespace tbs4 storage( .. .. ));

For more than one column:


Create table emp_part(empno number,ename varchar2(20),deptno number )
Partition by range (empno,deptno)
(partition part1 values less than (250,10)
tablespace tbs1 storage( .. .. ),
partition part2 values less than (500,20)
tablespace tbs2 storage( .. .. ));

Add a partition:

Alter table emp_part


add partition part5
values less than (maxvalue)
tablespace tbs5 storage(.. ..);

Split a partition:
Alter table emp_part
split partition part4
at (2000) into partition part4a, partition part4b);

Merge partition(only adjacent partitions can be merged):


Alter table emp_part
merge partition part1, part2
into partition part1_2
tablespace tbs_new;

Moving a partition:

Alter table emp_part


move partition part5
tablespace tbs_new;

Truncating a partition:
Alter table emp_part
truncate partition part3;

Dropping a partition:
Alter table emp_part
drop partition part3;

Select:
Select * from emp_part partition(part2);

Hash partition:

Create table emp_part(empno number,ename varchar2(20) )


Storage(... ...)
Partition by hash (empno)
(partition part1 tablespace tbs1,
partition part2 tablespace tbs2,
partition part3 tablespace tbs3);

In hash partition, it is not possible to split, merge or drop partition.


Add a partition:
Alter table emp_part
add partition part4 tablespace tbs5;

Composite partition: (Range and Hash)

Create table comp_part(empno number,ename


Partition by range (deptno)
Subpartition by hash(empno)
(partition part1 values less than (10)
(subpartition part1_sub1 tablespace
Subpartition part1_sub2 tablespace
Subpartition part1_sub3 tablespace
partition part2 values less than (40)
(subpartition part2_sub1 tablespace
Subpartition part2_sub2 tablespace
Subpartition part2_sub3 tablespace

varchar2(20),deptno number )

tbs1,
tbs2,
tbs3),
tbs5,
tbs6,
tbs7));

Add partition:

Alter table comp_part


Modify partition part2 add subpartition part2_sub4
Tablespace tbs8;

Rename partition:

Alter table comp_part


rename subpartition part2_sub4 to part2_sub5;

Select partition:
Select * from comp_part subpartition(part2_sub2);

List partition: (location, gender, product table etc)

Create table list_table (empno number,ename varchar2(30),state


varchar2(30))
Partition by list (state)
(partition part1 values(KAR, KER, TMN, AP),
partition part2 values(PUN, HAR, WB),
partition part3 values(ORS, MAH, GUJ));

VIEWS:
USER_TABLES
USER_PART_TABLES
USER_TAB_PARTITIONS
USER_TAB_SUBPARTIONS

Index organized table:


Create table iot_tab(empno number(4) constraint iot_tab_pk primary key,
Ename varchar2(20), address.. ..)

organization index
tablespace index_tbs
pctthreshold 50
including address
overflow tablespace of_tbs;

Cluster table:
1. Create cluster
Create cluster emp_clust(deptno number(5))
Tablespace data_clust
Storage(....)
Pctfree 10
Pctused 40
Initrans 2
Maxtrans 255;

2. Create index
Create index emp_clust_idx
On cluster emp_clust
Tablespace idx;

3. Create tables
Create table dept(deptno number(5), dname varchar2(50))
Cluster emp_clust(deptno);
Create table emp(eno number(5), ename varchar2(30), deptno number(5))
Cluster emp_clust(deptno);

Drop cluster:

Drop cluster emp_clust;

[ can be dropped only if empty ]

Drop cluster emp_clust including tables;


Drop cluster emp_clust including tables cascade constraints;

Temporary table:
Transaction specific table:
Create global temporary table glob_tab (empno number(4) )
On commit delete rows;

Session specific table:


Create global temporary table glob_tab (empno number(4) )
On commit preserve rows;

Indexes:
Creating Index:

Create index emp_idx on emp(empno)


Tablespace idx
Storage(initial 5m next 5m minextents 1 pctincrease 0)
Pctfree 10
Initrans 2
Maxtrans 255
Logging
Sort;

Das könnte Ihnen auch gefallen