--查詢表空間使用情況
select a.tablespace_name,total,free,total-free used from
( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files
group by tablespace_name) a,
( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space
group by tablespace_name) b
where a.tablespace_name=b.tablespace_name;
--查詢表空間信息
select * from dba_data_files;
--創建表空間
create tablespace myspace datafile
'D:\app\ADMINISTRATOR\oradata\myspace\myspace.dbf' size 20m autoextend on next 1m maxsize 50m;
create tablespace myspace01 datafile
'D:\app\ADMINISTRATOR\oradata\myspace\myspace01.dbf' size 20m autoextend on next 1m maxsize 50m;
--添加表空間數據文件
alter tablespace myspace ADD DATAFILE 'D:\APP\ADMINISTRATOR\ORADATA\myspace\myspace_01.DBF' SIZE 5M;
--刪除表空間數據文件
ALTER TABLESPACE myspace DROP DATAFILE 'D:\APP\ADMINISTRATOR\ORADATA\myspace\myspace_01.DBF';
--刪除表空間
drop tablespace myspace including contents and datafiles;
including contents 刪除表空間的同時,刪除表空間上的所有數據對象
and datafiles 表示刪除表空間的同時,刪除表空間所對應的數據文件
--將一個表空間下的表移動到新的表空間下
SELECT 'ALTER TABLE '||TABLE_NAME||' MOVE TABLESPACE TABLESPACE_NAME_NEW ;' FROM USER_TABLES WHERE TABLESPACE_NAME='TABLESPACE_NAME_OLD';
ALTER TABLE TABLE_NAME MOVE TABLESPACE TABLESPACE_NAME_NEW ;
--移動表空間中的數據文件
alter tablespace myspace offline;
alter tablespace myspace rename datafile 'D:\app\Administrator\oradata\myspace\myspace02.dbf' to 'E:\myspace02.dbf'
alter tablespace myspace online;