Oracle基础-表空间
閱讀時間:全文 387 字,預估用時 2 分鐘
創作日期:2017-07-21
上篇文章:Oracle基础-数据表
下篇文章:Oracle数据类型
BEGIN
表空间的分类
- 永久表空间:表,视图,存储过程
- 临时表空间:数据库操作过程中的中间执行的过程,执行完后会被释放掉
- Undo表空间:保存数据表修改前的信息储存。
表空间的操作
- 创建表空间:
create tablespace ts_name datafile 'D:\oracle\data\firstspace.dbf' size 20M autoextend on next 5M maxsize 500M;
创建名为firstspace的表空间,文件名及路径为D:\oracle\data\firstspace.dbf,初始大小为20M,开启自动拓展,每次加5M,最大上限为500M。 - 查看表空间名及路径:
select ts_name, file_name from dba_data_files;
- 查看用户信息:
select user_id,username,default_tablespace from dba_users order by username;
- 修改默认表空间为firstspace:
alter database default tablespace ts_name;
此时默认表空间为firstspace而不是users。 - 更改表空间名称:
alter tablespace ts_name rename to username;
此时表空间名firstspace改为username。 - 创建用户:
create user ct identified by ct123? default tablespace users temporary tablespace temp;
创建用户ct,密码为ct123?,默认表空间为users,临时表空间为temp。 - 用户表空间的数据字典,dba_tablespaces、user_tablespaces和dba_users、user_users
- 设置表空间的脱机的状态:
alter tablespace ts_name offline;
- 设置表空间的联机状态:
alter tablespace ts_name online;
- 修改表空间为只读状态:
alter tablespace ts_name read only;
- 修改表空间为读写状态:
alter tablespace ts_name read write;
- 表空间增加数据文件:
alter tablespace ts_name add datafile '/path/xxx.dbf' size 20M;
- 表空间删除数据文件:
alter tablespace ts_name drop datafile '/path/xxx.dbf';
- 仅删除表空间:
drop tablespace ts_name;
- 删除表空间并同时删除对应表空间下的所有内容及文件:
drop tablespace ts_name including contents and datafiles;
FINISH
上篇文章:Oracle基础-数据表
下篇文章:Oracle数据类型