How To Use Tablespace In OraclePLSQL
Description
Tablespace stores schema objects like tables, indexes, view etc. logically into the tablespace and physically in the datafiles related to the corresponding tablespace.
Datafiles
- Physical files
- dbf extension
- Store schema objects
- Written by database writer processes
- Table space are logical entity
Example
In this example, you will see, how to create and drop tablespace in Oracle.
- Select name from v$tablespace;
- Select name from v$datafile;
- create tablespace mytbs datafile 'c:\app\mcntr004\oradata\pnt\datafile\mytbs1.dbf' size 100m;
- Select ts#, name from v$datafile;
Using Alter table in table space
Example
- alter tablespace mytbs add datafile 'c:\app\mcntr004\oradata\pnt\datafile\mytbs2.dbf' size 100m;
- select ts#, name from v$datafile;
- desc dba_tablespaces;
- select tablespace_name, status from dba_tablespaces;
- alter database datafile 'c:\app\mcntr004\oradata\pnt\datafile\mytbs1.dbf' resize 200m;
- desc v$datafile;
- alter tablespace mytbs read only;
- alter tablespace mytbs read write;
- alter tablespace mytbs force logging;
- alter tablespace mytbs nologging;
- alter tablespace yourtbs rename to mytbs;
- select name from v$tablespace;
Drop Tablespace
- drop tablespace mytbs including contents and datafiles;
- select name from v$tablespace;
Summary
Thus, we learnt, tablespace stores the schema objects like tables, indexes, view etc. logically into the tablespace and physically in the datafiles related to the corresponding tablespace. We learnt, how to use tablespace in Oracle with the examples.