1、创建一般tablespace
create tablespace xifenfei datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\
xifenfei.DBF’ size 10m reuse autoextend on next 10m maxsize UNLIMITED ;
2、创建temp tablespace
create temporary tablespace xff_temp tempfile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\xff_temp.dbf’ size 10m;
3、创建undo tablespace
create undo tablespace xff_undo datafile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\xff_undo.dbf’ size 10m;
4、更改数据库的默认临时表空间
alter database default temporary tablespace xff_temp;
5、查询表空间类型
select tablespace_name,contents from dba_tablespaces;
6、查询默认临时表空间
select * from database_properties where property_name like ‘%TEMP_TABLE%’;
7、表空间变为只读状态
alter tablespace xifenfei read only;
note:该表空间中的objects可以被drop,因为表的记录是放在数据字典(system)中
8、表空间变为读写状态
alter tablespace xifenfei read write;
9、表空间offline
alter tablespace xifenfei offline;
note:如果有数据没有commit,会自动被commit掉
10、表空间online
alter tablespace xifenfei online;
11、查看表空间剩余大小
select f.tablespace_name,a.total,u.used,f.free,round((u.used/a.total)*100) "% used", round((f.free/a.total)*100) "% Free"
from
(select tablespace_name, sum(bytes/(1024*1024)) total
from dba_data_files group by tablespace_name) a,
(select tablespace_name, round(sum(bytes/(1024*1024))) used
from dba_extents group by tablespace_name) u,
(select tablespace_name, round(sum(bytes/(1024*1024))) free
from dba_free_space group by tablespace_name) f
WHERE a.tablespace_name = f.tablespace_name and a.tablespace_name = u.tablespace_name order by "% Free";
12、表空间自增长
alter database datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\XIFENFEI.DBF
‘ autoextend on next 2m maxsize 100m;
13、表空间中添加数据文件
alter tablespace xifenfei add datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\OR
CL\XIFENFEI1.DBF’ size 20m;
14、查看表空间是否是自增长
select file_name,autoextensible from dba_data_files;
15、修改表空间大小
alter database datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\
XIFENFEI1.DBF’ resize 15m;
16、查询临时表空间
select tablespace_name,file_name from dba_temp_files;
17、datafile rename
1)alter tablespace xifenfei rename datafile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\ XIFENFEI1.DBF’ to
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\abc\ XIFENFEI1.DBF’
note:target文件必须存在,表空间必须离线
2) alter database rename file ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\XIFENFEI1.DBF’
to ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\orcl\XIFENFEI1.DBF’
note:target文件必须存在,数据库必须mount状态
18、删除表空间中的某个datafile
alter tablespace xifenfei drop datafile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\XIFENFEI1.DBF’;
19、删除表空间
drop tablespace xifenfei including contents and datafiles;