Oracle之表空间
前置介绍
工具:PL/SQL
表空间介绍
表空间是用于存储表的一个物理空间,用户在操作时实际上是操作表空间内的表,一个表空间可以对应多个表,而一个表只能对应一个表空间。每一个用户需要指定一个表空间来存放表,如果没有指定时则会使用默认表空间。
创建表空间
注:创建表空间的操作需要在system用户中执行。
create tablespace test_tb
datafile 'c:\test.dbf'
size 100m
autoextend on next 32m maxsize unlimited;
create tablespace 创建表表空间,后跟表空间名
datafile 创建表空间的物理位置
size 创建表空间的大小
autoextend on 自动增长
next 32m maxsize unlimited; 每次增加32M没增长上限
即创建的表空间达到上限时每次以32M的内存增加内存,没有增长上限,可以无限增长。
注:可添加 extent management local 来优化。

删除表空间
drop tablespace test_tb1 including contents and datafiles;
including contents 删除表空间中的内容(此选项必须添加)
including datafiles 删除表空间中的数据文件

表空间操作
(1)查询所有表空间名称
select tablespace_name from dba_tablespaces;

(2)表空间改名
alter tablespace test_tb rename to test_tb1;

(3)设置只读表空间
alter tablespace tabs read only;
(4)设置可读写表空间
alter tablespace tabs read write;
使用表空间
表空间的使用一般是在创建用户的时候给用户添加表空间,此时可以给创建的用户指定表空间。
create user hpe
identified by system
default tablespace test_tb1;

注:表空间包含临时表空间和默认空间。
临时表空间用来管理数据库排序操作以及用于存储临时表、中间排序结果等临时对象。