oracle 11g 表空间 增删改查
#建立表空间
CREATE TABLESPACE data01
DATAFILE 'd:\app\test.dbf' SIZE 500M
UNIFORM SIZE 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
/*-------------------------------------------------------------------------*/
CREATE TABLE userinfo #创建表
(
id VARCHAR2(32) NOT NULL,
name VARCHAR2(32) NOT NULL,
password VARCHAR2(32) NOT NULL,
CONSTRAINT userinfo_pk PRIMARY KEY (id),
CONSTRAINT userinfo_unique_name UNIQUE ( name )
)
TABLESPACE data01;
/*--------------------------------------------------------------------------*/
#建立UNDO表空间
CREATE UNDO TABLESPACE UNDOTBS02
DATAFILE 'd:\app\UNDOTBS02.dbf' SIZE 50M;
/*---------------------------------------------------------------------------*/
#建立临时表空间
CREATE TEMPORARY TABLESPACE temp_data
TEMPFILE 'd:\app\TEMP_DATA.dbf' SIZE 50M
/*---------------------------------------------------------------------------*/
/* 查看数据文件资料,[where语句]可指定某空间,eg. SAMPLE01,USERS01
select file_name, tablespace_name
from dba_data_files
[where tablespace_name ='<name of tablespace>'];
#或者:
Select file#,name from v$datafile;
/*---------------------------------------------------------------------------*/
#修改表空间大小
alter database datafile ' d:\app\test.dbf ' resize 100M
/*---------------------------------------------------------------------------*/
##扩展表空间##
#首先查看表空间的名字和所属文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
#增加数据文件(表空间大小)
ALTER TABLESPACE data01
ADD DATAFILE 'd:\app\test2.dbf' SIZE 1000M;
#设定数据文件自动扩展
ALTER DATABASE DATAFILE 'd:\app\test.dbf'
AUTOEXTEND ON NEXT 100M
MAXSIZE 10000M;
#设定后查看表空间信息
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
(B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE"
FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME;
/*---------------------------------------------------------------------------*/
#移动表至另一表空间
alter table <tablename> move tablespace <to_tablespace_name>;
#其中<tablename>为一表名,eg employee ; <to_tablespace_name>为一表空间名,eg data01
#eg. alter table userinfo move tablespace sample01;
/*---------------------------------------------------------------------------*/
#改变表空间状态 使表空间脱机
ALTER TABLESPACE data01 OFFLINE;
#使表空间联机
ALTER TABLESPACE data01 ONLINE;
#使表空间只读
ALTER TABLESPACE data01 READ ONLY;
#使表空间可读写
ALTER TABLESPACE data01 READ WRITE;
/*---------------------------------------------------------------------------*/
#删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
#如果是意外删除了数据文件,则必须带有RECOVER选项
ALTER TABLESPACE data01 OFFLINE FOR RECOVER;
posted on 2013-07-29 15:41 阳光总在风雨后001 阅读(2288) 评论(0) 编辑 收藏 举报