Interview Questions

Oracle TableSpace

Tablespace
A Tablespace in Oracle represents a location where the actual data related to tables, indexes will be stored. A database consists of one or more tablespace (tablespace made up of one or more datafiles).

Types of Tablespace
The different types of tablespace are as follows,
1. Permanent tablespace
- It contains the persistent schema objects which are stored in the data files.

2. Undo tablespace
- Oracle database maintains the set of information, data records which are used to perform database roll back, recovery operations etc. These are maintained in the undo tablespace when Oracle database is running in Automatic Undo Management Mode.

3. Temporary tablespace
- Data or information used for the session duration are stored in the Temporary tablespace.
- These objects are stored in Temp files.

Tablespace operations
To create a tablespace first login as "sysdba" account type in Oracle.

To create a table space, use the following statement.

CREATE TABLESPACE TECHDIVE_DATA DATAFILE 'C:\oracle\product\10.2.0\oradata\techdive\techdiveData.dbf'   SIZE 10m AUTOEXTEND ON NEXT 5M;

This data file specified in the tablespace will be used to store the data for tables, indexes etc., when you create a table you may or may not specify a table space. If it is not mentioned then the data will be stored in the default table space 'SYSTEM'.

The size specified for this tablespace is just 10 MB. But when more data need to be stored, it automatically extends the size by 5 MB.

To drop a tablespace use the following command.

DROP TABLESPACE TECHDIVE_DATA;

To view the list of tablespace data in the database use the following query.

SELECT * FROM DBA_TABLESPACES;

To view the data file related information use the following query.

SELECT * FROM dba_data_files