1 熟悉与表空间相关的数据字典
1.1 Dba_tablespaces 管理员用户级别使用
查看用户的表空间
例:
Select tablespace_name from dba_tablespaces;
1.2 User_tablespaces 普通用户使用 表的字段也不一样
查看用户的表空间
Select tablespace_name from user_tablespaces;
普通用户如scott,不能查看管理员权限的数据字典
1.3 Dba_users 针对管理员的数据字典,查看数据库所有用户的用户信息
查看system用户的表空间信息
Select default_tablespace, temporary_tablespace from dba_users where username =’SYSTEM’;
查看用户默认表空间临时表空间。
设置用户默认或临时的表空间
语法格式:
Alter user username default| temporary tablespace tablespace_name;
例:
Alter user user01
default tablespace test1_tablespace
temporary tablespace temptest1_tablespace;
1.4 User_users 普通用户使用 , 查看当前连接用户的信息。
2 修改表空间的状态
2.1 设置联机或脱机状态
Alter tablespace tablespace_name online|offline;
特别说明:
如果一个表空间设置成脱机状态,表示该表空间暂时不让访问,设置成脱机装填不删除,当我们需要使用该表空间时还可以将其设置成联机状态,正常使用。
2.2 设置只读或可读写装填
Alter tablespace tablespace_name
Read only| read write;
默认是可读写状态
3 修改表空间的数据文件
3.1 增加数据文件
语法格式
Alter tablespace tablespace_name
Add datafile ‘filename.dbf’ size xx;
说明:
像创建好的表空间里增加数据文件
3.2 删除数据文件
语法格式
Alter tablespace tablespace_name
Drop datafile ‘filename.dbf’;
说明
不能删除表空间中第一个创建的数据文件,如果需要删除的话,我们需要把整个的表空间删掉。
4 删除表空间
语法格式
Drop tablespace tablespace_name [including contents]
说明:
- 如果删除时只想单纯的删除表空间,而不删数据文件的话,可以如下
Drop tablespace tablespace_name; - 如果一同删除的话,需添加入下
Including contents