SQL表空间

---建表的时候指定表空间 表空间----1个或者多个文件 ==》 往表中插入数据,实际是插入 建表时指定的表空间对应的文件当中。


1. 创建自己的表空间

create tablespace myspace datafile 'C:\app\EDY\oradata\orcl\myspace.dbf' size 200m;
create table my_space_test (id number) tablespace myspace;
insert into my_space_test values(1);
commit;

2. 在表空间下增加新的数据⽂件,并设置数据⽂件⼤⼩

Alter tableplace tableplace_name
Add datafile ‘数据⽂件保存⽬录/数据⽂件.dbf’
Size ;

例题:假设表空间neuspace已⽤尽500MB空间,现要求增加⼀个数据⽂件,存放在e:\appdata⽬录下,⽂件名为appneudata,⼤⼩为500MB,不⾃动增长

Alter tablespace neuspace add 
datafile 'e:/ appdata/appneudata.dbf'
size 500M;

3. 查看所有的表空间

select * from DBA_TABLESPACES;

4. 查看某个⽤户的默认表空间

select default_tablespace, username
from dba_users
where username = '⽤户名';

5. 查看表空间剩余容量

select tablespace_name, sum(bytes)
from dba_free_space
group by tablespace_name;

6. 给表空间重命名

alter tablespace tablespace_name rename to new_tablespace_name;

7.设置表空间的读写状态

alter tablespace tablespace_name READ ONLY;——只读
alter tablespace tablespace_name READ WRITE ;——读写

8. 设置表空间的可⽤状态

alter tablespace tablespace_name ONLINE;——联机
alter tablespace tablespace_name OFFLINE NORAML / TEMPORARY / IMMEDIATE;——⽴即切换到脱机状态

注释:将表空间设置为脱机状态时应尽量使⽤NORAML⽅式,这样在将表空间恢复到联机状态时不需要进⾏数据库恢复,只有⽆法使⽤
NORAML进⼊脱机状态时,采⽤TEMPORARY。以上两种⽅式都失败时才使⽤IMMEDIATE⽅式。
9. 建⽴⼤⽂件表空间

Create BIGFILE tablespace tablespace_name
Datafile ‘数据⽂件保存⽬录/数据⽂件.dbf’
Size(⼤⼩);

10. 删除表空间

DROP tablespace tablespace_name INCLUDING CONTENTS;----把表空间⾥的数据⽂件删除
DROP tablespace tablespace_name CASCADE CONSTRAINTS;-----把表空间中的完整的删除

 

posted @   潜摩羯  阅读(216)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示