文章目录
1 简介
在进行表空间的管理之前,必须先了解Database(数据库)、Tablespace(表空间)、Table(表)的关系。
一个Oracle 11g 数据库系统可以建立多个数据库(推荐一个数据库),一个数据库可以建立多个表空间,一个表空间可以建立多个表,可由上图清楚的看出它们之间的关系。
2 创建表空间
2.1 创建TS1表空间
以system连接orcl数据库
create tablespace ts1 datafile
'D:\Oracle\oracle\app\Administrator\oradata\orcl\test_db01.dbf' size 100M
autoextend on next 100M maxsize 1024M
default storage (initial 10M next 1M)
permanent
online
logging;
2.2 创建TS4表空间,并在表空间中创建表
第一步:创建TS4表空间
create tablespace ts4 datafile
'D:\Oracle\oracle\app\Administrator\oradata\orcl\test_db04.dbf' size 100M
autoextend on next 100M maxsize 1024M
default storage (initial 10M next 1M)
permanent
online
logging;
第二步:在表空间创建表
create table customer(
custId varchar2(10),
custName varchar2(22),
custAdd varchar2(20),
custPhone varchar2(12),
custFax varchar2(12)
)
tablespace ts4;
如果在创建表时未指定表空间,那就表示设置了默认表空间(一般是在users中),否则就会出现错误。
3 修改表空间
3.1 修改表空间的记录属性
alter tablespace ts1
nologging;
3.2 把表空间改为离线状态
alter tablespace ts1
offline;
3.3 把表空间改为连线状态
alter tablespace ts1
online;
3.4 在表空间中添加数据文件
扫描二维码关注公众号,回复:
12886578 查看本文章
alter tablespace ts1 add datafile
'D:\Oracle\oracle\app\Administrator\oradata\orcl\test_db02.dbf' size 100M reuse
autoextend on next 100M maxsize unlimited;
此时在上述文件夹下就会生成test_db02.dbf文件。
在建立表空间时,若是约束了表空间的大小,那么一段时间后,这个表空间就会被装满,无法再添加其他对象。这时就需要给表空间添加文件(add datafile)
4 删除表空间
4.1 直接删除表空间(未删除数据文件)
drop tablespace ts1;
4.2 删除表空间(同时删除数据文件)
第一步:创建一个TS3表空间
create tablespace ts3 datafile
'D:\Oracle\oracle\app\Administrator\oradata\orcl\test_db03.dbf' size 100M
autoextend on next 100M maxsize 1024M
default storage (initial 10M next 1M)
permanent
online
logging;
第二步:删除表空间,同时删除数据文件
drop tablespace ts3 including contents and datafiles;
至此,表空间的基本管理已经介绍完毕。