This Oracle tutorial explains how to use the Oracle CREATE TABLESPACE statement with syntax and examples.
Description
The CREATE TABLESPACE statement is used to allocate space in the Oracle database where schema objects are stored.
The CREATE TABLESPACE statement can be used to create the 3 kinds of tablespaces:
Permanent Tablespace
Temporary Tablespace
Undo Tablespace
We will take a look at all 3 kinds of tablespaces.
#1 - PERMANENT TABLESPACE
A permanent tablespace contains persistent schema objects that are stored in data files.
Syntax
The syntax for the CREATE TABLESPACE statement when creating a permanent tablespace is:
SMALLFILE
A tablespace that contains 1,022 data or temp files (each file can be up to 4 million blocks in size). This is the most common tablespace size to create.
BIGFILE
A tablespace that contains only one data or temp file (this file can be up to 4 million blocks in size).
TIP: If you omit the SMALLFILE or BIGFILE option, the Oracle database will use the default tablespace type.
tablespace_name
The name of the tablespace to create.
storage_clause
The syntax for the storage_clause is:
Example - PERMANENT TABLESPACE
The following is a CREATE TABLESPACE statement that creates a simple permanent tablespace:
This CREATE TABLESPACE statement creates a permanent tablespace called tbs_perm_01 that has one data file called tbs_perm_01.dat.
The following is a CREATE TABLESPACE statement that creates a permanent tablespace that will extend when more space is required:
This CREATE TABLESPACE statement creates a permanent tablespace called tbs_perm_02 that has one data file called tbs_perm_02.dat. When more space is required, 10M extents will automatically be added until 200MB is reached.
The following is a CREATE TABLESPACE statement that creates a BIGFILE permanent tablespace that will extend when more space is required:
This CREATE TABLESPACE statement creates a BIGFILE permanent tablespace called tbs_perm_03 that has one data file called tbs_perm_03.dat.
#2 - TEMPORARY TABLESPACE
A temporary tablespace contains schema objects that are stored in temp files that exist during a session.
Syntax
The syntax for the CREATE TABLESPACE statement when creating a temporary tablespace is:
SMALLFILE
A tablespace that contains 1,022 data or temp files (each file can be up to 4 million blocks in size). This is the most common tablespace size to create.
BIGFILE
A tablespace that contains only one data or temp file (this file can be up to 4 million blocks in size).
TIP: If you omit the SMALLFILE or BIGFILE option, the Oracle database will use the default tablespace type.
tablespace_name
The name of the tablespace to create.
Example - TEMPORARY TABLESPACE
The following is a CREATE TABLESPACE statement that creates a temporary tablespace:
This CREATE TABLESPACE statement creates a temporary tablespace called tbs_temp_01 that has one temp file called tbs_temp_01.dbf.
#3 - UNDO TABLESPACE
An undo tablespace is created to manage undo data if the Oracle database is being run in automatic undo management mode.
Syntax
The syntax for the CREATE TABLESPACE statement when creating an undo tablespace is:
SMALLFILE
A tablespace that contains 1,022 data or temp files (each file can be up to 4 million blocks in size). This is the most common tablespace size to create.
BIGFILE
A tablespace that contains only one data or temp file (this file can be up to 4 million blocks in size).
TIP: If you omit the SMALLFILE or BIGFILE option, the Oracle database will use the default tablespace type.
tablespace_name
The name of the tablespace to create.
Example - UNDO TABLESPACE
The following is a CREATE TABLESPACE statement that creates an undo tablespace:
This CREATE TABLESPACE statement creates an undo tablespace called tbs_undo_01 that is 5MB in size and has one data file called tbs_undo_01.f.