Oracle数据库 表空间

  • 2021-11-10
  • Admin
--查看表空间
select * from v$tablespace;
--查看表空间中的数据文件
desc dba_data_files;--在Command Window中运行
--查看详细的数据文件
select file_name,tablespace_name from dba_data_files;

--查询SYSTEM用户的默认表空间 eg:用户名称要大写
select default_tablespace from dba_users where username='SYSTEM';
--查询SCOTT用户的默认表空间
select default_tablespace from dba_users where username='SCOTT';
--查询SYSTEM用户的临时表空间
select Temporary_tablespace from dba_users where username='SYSTEM';
--查询SCOTT用户的临时表空间
select Temporary_tablespace from dba_users where username='SCOTT';

--查询永久表空间
select property_name,property_value from database_properties;--老师为1条记录,我是13条
--查询普通用户拥有的表空间
select username,temporary_tablespace from dba_users;
--查询当前用户拥有的表空间
---不同的用户会使用不同的表空间
desc dba_tablespaces;--Command Window

--创建表空间 第一章PPT第35张
---创建表空间的语法:
----create tablespace 表空间 datafile'指定数据文件的位置' size 大小(autoextend on 表空间不够自动增长 next 设置自动大小)
-----创建一个名为crm的表空间
create tablespace tab_sp_crm datafile'D:\crm.dbf' size 100M;
--查询当前用户
select username,temporary_tablespace from dba_users;
select * from dba_data_files where file_name='tab_sp_crm';

--创建一个名为crms的临时表空间 在create后添加temporary,数据文件使用tempfile
create temporary tablespace tab_sp_crms tempfile'D:\crms.dbf' size 100M;
-- 查看表空间的具体路径
desc dba_data_files;--在Command Window中运行
select file_name,tablespace_name from dba_data_files;

--设置用户的默认或临时表空间(普通用户没有设置表空间的权限)
---语法:alter user username default|temporary tablespace tablespace_name;
---将tab_sp_crms临时表空间指定给SCOTT用户
alter user scott temporary tablespace tab_sp_crms;
--查询SCOTT用户的临时表空间
select Temporary_tablespace from dba_users where username='SCOTT';

-- 添加数据文件
---<1>如果是给已存在的表空间添加数据文件,则使用:
----alter tablespace 表空间名称 add datafile'数据文件名称' size 大小;
alter tablespace tab_sp_crm add datafile'D:\crmadd.dbf' size 50M;
---<2>新建表空间的时候同时添加数据文件
----create tablespace 表空间 datafile'指定数据文件的位置' size 大小;


--练习:
---创建一个名为tab_sp_student的表空间,并添加名为student.dbf的数据文件
create tablespace tab_sp_student datafile'D:\student.dbf' size 50M;
----给已创建好的tab_sp_student表空间添加一个名为student2.dbf的数据文件
alter tablespace tab_sp_student add datafile'D:\student2.dbf' size 50M;
---创建一个名为tab_sp_student3的临时表空间并添加名为student3.dbf的数据文件并将这个表空间指定给scott用户
create temporary tablespace tab_sp_student3 tempfile'D:\student3' size 100M;
alter user scott temporary tablespace tab_sp_student3;


--删除表空间
---语法:drop tablespace 表空间名称 including contents and datafiles
---删除SCOTT用户的临时表空间tab_sp_crms;
drop tablespace tab_sp_crms including contents and datafiles;

drop tablespace tab_sp_student3 including contents and datafiles;

--重命名表空间
---语法:alter tablespace 原表空间名称 rename 新表空间名称;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

原文:https://blog.csdn.net/cwx2352265318/article/details/121257648

联系站长

QQ:769220720