表空间

一.创建表空间

create tablespace test    //其中test为表空间名

datafile 'D:study est.dbf' size 10M     //指定路径和表空间大小

autoextend on next 5M     //允许自动扩展,每次扩展5M

extent management local uniform size 800K ||autoallocate

//决定表空间是数据字典管理方式还是本地化管理方式。可使用关键字uniform和autoallocate。

unifrom:后面可以添加规定每个区的大小的语句(size ??),若不添加,则默认每个区大小为1M

autoallocate:盘区大小自动分配,为默认选项

segment space management manual ||auto//表空间的管理方式,manual为手动,auto为自动方式。

2.管理表空间

1.为表空间增加新的数据文件,并且指定自动扩展属性

alter tablespace test     //选择表空间

add datafile 'D:study s01.dbf' size 10M  //增加数据文件,其中数据文件ts01.dbf本不存在,是新创建的,大小必须指定。

autoextend on next 5M  //指定自动扩展属性

2.修改数据文件大小

select tablespace_name,file_id,bytes,blocks from dba_free_space;   //通过数据字典dba_free_space,了解表空间的分区情况

alter database datafile 'D:study s01.dbf' resize 10M;     //修改大小

3.移动数据文件

alter tablespace test offline//将要修改的表空间设置为offline状态

alter tablespace test      //选择表空间

rename datafile 'D:study s01.dbf' to 'E:study s01.dbf';   //将数据文件移动另外的磁盘

4.删除表空间

drop tablespace test;   //删除表空间

drop tablespace test including contents and datafiles;    //删除表空间和其内的所有内容和数据文件

原文地址:https://www.cnblogs.com/jfl-xx/p/4600850.html