oracle数据库笔记1oracle表空间

与表空间有关的系统权限:

create tablespace、alter tablespace、drop tablespace、 manage tablespace和unlimited tablespace等。

创建一个名为DATATEST的表空间:

create tablespace DATATEST datafile 'C:\oracle\product\10.2.0\oradata\orcl\DATATEST.dbf' size 100M autoextend ON next 10M maxsize 200M;

创建一个名为DATATEST_TEMP的临时表空间:

create temporary tablespace DATATEST_TEMP tempfile 'D:\SERVER\DATABASE\ORACLE\PRODUCT\10.2.0 \ORADATA\ORCL\DATATEST_TEMP.dbf' size 50M autoextend ON next 10M maxsize 100M; ;

使一个表空间脱机:

SQL>alter tablespace<tablespace_name>offline; SQL>alter tablespace dalianren offline;

使一个表空间联机:

SQL>alter tablespace<tablespace_name>online; SQL>alter tablespace dalianren online;

使表空间只读命令格式:

SQL>alter tablespace<tablespace_name>read only; SQL>alter tablespace dalianren read only;

使表空间可读可写命令格式:

SQL>alter tablespace<tablespace_name>read write; SQL>alter tablespace dalianren read write;

添加临时表空间的数据文件:

SQL>alter tablespace<tablespace_name>add tempfile ′<path_and_file_name>′size<n>m;

SQL>alter tablespace temp_ren add tempfile ′D:\oracle\product\10.2.0\oradata\dalian\temp_ren.dbf′size 100m;

调整临时表空间的数据文件:

SQL>alter database tempfile ′<path_and_file_name>′resize<mega_bytes>m;

SQL>alter database tempfile ′D:\oracle\product\10.2.0\oradata\test \temp_ren.ora′ resize 20m;

将表空间的数据文件或临时文件脱机:

SQL>alter database  datafile′<path_and_file_name>′ offline;

SQL>alter database tempfile ′<path_and_file_name>′ offline;

SQL>alter database  datafile ′D:\oracle\product\10.2.0\oradata\dalian\temp_ren.ora′ offline;

SQL>alter database  tempfile ′D:\oracle\product\10.2.0\oradata\dalian\temp_ren.ora′offline;

将临时表空间联机:

SQL>Alter database tempfile ′<path_and_file_name>′online;

SQL>Alter database tempfile ′D:\oracle\product\10.2.0\oradata\dalian\temp_ren.ora′ online;

删除表空间,但不删除其文件:

SQL>drop tablespace<tablespace_name>;

SQL>drop tablespace dalianren;

删除包含目录内容的表空间

SQL>drop tablespace<tablespace_name>including contents;

例删除表空间dalianren及其包含的内容

SQL>drop tablespace dalianren including contents;

删除包含目录内容和数据文件在内的表空间

SQL>drop tablespace<tablespace_name>including contents and datafiles;

例删除表空间dalianren及其包含的内容以及数据文件

SQL>drop tablespace dalianren including contents and datafiles;

当含有参照性约束时,删除包含目录内容和数据文件在内的表空间:

SQL>drop tablespace<tablespace_name>including contents and datafiles cascade constraints;

例将表空间dalianren及其包含的内容、数据文件以及相关约束一同删除

SQL>drop tablespace dalianren including contents and datafiles cascade constraints;

表空间更名:Oracle9i中不能直接将表空间更名。在Oracle 10g可直接更名永久表空间和临时表空间。 但是,system和sysaux表空间不能更名。

命令格式:

SQL>alter tablespace<old_tablespacename>rename to<new_tablespacename>;

SQL>alter tablespace users rename to newusers;

多重临时表空间:

在Oracle 10g中增加了一个表空间组的概念,通过使用表空间组用户可以使用一个以上的表空间存储临时段。

表空间组是在第一个表空间被指定给该组时,由系统自动隐式创建的。

例如:

通过添加现有的表空间创建表空间组。

SQL>alter tablespace temp tablespace group temp_ts_group;

添加一个新的表空间给该已经创建的表空间组:

SQL>create temporary tablespace temp2 tempfile ′D:\oracle\product\10.2.0\oradata\test\temp201.dbf ′ size 20m  tablespace group temp_ts_group;

被指定给组的表空间可在视图中查询得到:

SQL>select*from dba_tablespace_groups; group_nametablespace_name temp_ts_grouptemp temp_ts_grouptemp2 2 rows selected.

一旦创建了表空间组,就可以将其指定给用户或作为默认的临时表空间,就像一个表空间一样

将表空间组指定给用户,作为临时表空间:

SQL>alter user scott temporary tablespace temp_ts_group;

将表空间组作为默认的临时表空间:

SQL>alter database default temporary tablespace temp_ts_group;

表空间也可以从表空间组中移出:

SQL>alter tablespace temp2 tablespace group;

查询表空间组:

SQL>select*from dba_tablespace_groups;

group_nametablespace_name

--------------------------------------------------

temp_ts_grouptemp

1 row selected.

原文地址:https://www.cnblogs.com/wust221/p/3058613.html