Oracle 表空间的操作

1.[b]查看表空间的信息[/b]

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;


[b]2.创建表空间[/b]
SQL> create tablespace testspace    
datafile 'd:/OracleTest/test001.dbf' size 10m autoextend on next 5m maxsize unlimited
extent management local ;


[b]2.给表空间添加数据文件 [/b]

SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m    
autoextend on next 3m maxsize 50m;

SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m
autoextend on next 3m maxsize 50m;


[b]3.删除表空间中的数据文件 [/b]
SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf';   

SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf';


[b]4.修改表空间文件的数据文件大小 [/b]

SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m;  

SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m;


[b]5.修改表空间数据文件的自动增长属性 [/b]

SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off;   

SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off;


[b]6.修改表空间的读写属性 [/b]

SQL> alter tablespace testspace read only;(只读)    

SQL> alter tablespace testspace read write;(读写)

SQL> alter tablespace testspace read only;(只读)

SQL> alter tablespace testspace read write;(读写)


[b]7.设置表空间脱/联机 [/b]

SQL> alter tablespace testspace offline;    

SQL> alter tablespace testspace online;

SQL> alter tablespace testspace offline;

SQL> alter tablespace testspace online;


[b]8.转移物理文件路径的操作 [/b]

(1)设置表空间脱机 alter tablespac testspace offline;    

(2)物理转移表空间文件;即把你的表空间物理文件转移到你想移动的路径

(3)逻辑转移:alter tablespace testspace rename datafile 'd:/OracleTest/test001.dbf' to 'e:/test001.dbf';

(4)设置表空间联机 alter tablespace testspace online;

(1)设置表空间脱机 alter tablespac testspace offline;

(2)物理转移表空间文件;即把你的表空间物理文件转移到你想移动的路径

(3)逻辑转移:alter tablespace testspace rename datafile 'd:/OracleTest/test001.dbf' to 'e:/test001.dbf';

(4)设置表空间联机 alter tablespace testspace online;


[b]9.删除表空间 [/b]

(1)不删文件 drop tablespace testspace;    

(2)删除文件 drop tablespace testspace including contents and datafiles;

(1)不删文件 drop tablespace testspace;

(2)删除文件 drop tablespace testspace including contents and datafiles;


[b]10.物理文件被非法删除时,怎样启动数据库 [/b]

(1)关闭数据库服务 shutdown    

(2)alter database datafile 'd:/test001.dbf' offline drop;

(3)alter database open;

(4)开启数据库服务 startup;



[b]11、查看表空间名 [/b]


Select distinct Tablespace_Name from tabs;   
select tablespace_name from user_tablespaces;



实例: 创建表时关联表空间

-- Create tablespace
create tablespace tab_news datafile 'F:\oradata\NPMS\tab_news.dbf' size 5m autoextend on next 2m maxsize unlimited extent management local;

autoextend on next 2m 代表 以2m的大小自增

-- Create table
create table NEWS_BBS
(
BBSID NUMBER(10) not null,
PROJECT VARCHAR2(128) not null,
USERID NUMBER(10),
CONTENT CLOB,
ANSWERID NUMBER(10),
ANSWERCOUNT NUMBER(10),
PUBLISHTIME DATE
)
tablespace NEWS_TAB
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
minextents 1
maxextents unlimited
);

-- Create/Recreate primary, unique and foreign key constraints
alter table NEWS_BBS
add constraint PK_NEWS_BBS primary key (BBSID)
using index
tablespace ET_TAB
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值