SQL> create tablespace testtab datafile'/home/oracle/oradata/orcl/testtab1.dbf' size 100M autoextend on next 100M maxsize unlimited;
autoextend on next 100M:autoextend表示表空间大小自动扩展,on next 100M指定每次表空间满了之间扩展的大小
maxsize unlimited:maxsize指定表空间的最大存储值,unlimited表示不限制表空间的最大值(也就是只要硬盘不满,表空间就可以一直扩展)
SQL> create temporary tablespace testtemp tempfile'/home/oracle/oradata/orcl/testtemp1.dbf' size 100M autoextend on next 100M maxsize unlimited;
SQL> create user test default tablespace testtab temporary tablespace testtemp identified by 123456;
SQL> conn system/123456
SQL> grant create session to test;
SQL> select * from user_sys_privs;
SQL> select username,default_tablespace,temporary_tablespace from user_users;
表空间是数据库中最大的逻辑单位,一个 Oracle 数据库至少包含一个表空间,就是名为SYSTEM的系统表空间。每个表空间是由一个或多个数据文件组成的,一个数据文件只能与一个表空间相关联。表空间的大小等于构成该表空间的所有数据文件大小之和。
默认包含如下表空间(从v$tablespace中查看):SYSTEM、SYSAUX、TEMP、UNDOTBS1、USERS
SYSTEM是系统表空间,存放系统的最基本的信息,如果SYSTEM表空间坏掉,Oracle将无法启动。
SYSAUX从10g中引入,作为SYSTEM的辅助表空间,用以减少SYSTEM表空间的负荷 。以前其他表空间中的一些组件,现在放到SYSAUX表空间中了 。
TEMP是临时表空间,当排序不能在分配的空间中完成时,就会使用磁盘排序的方式,即在Oracle实例中的临时表空间中进行。
UNDOTBS1是撤销表空间,是UNDO类型的表空间,保存用户进行DML操作中,修改前的数据。
USERS是数据库默认的永久表空间。
创建表空间
–查询当前用户默认表空间
select default_tablespace from user_users;
–创建表空间:
create tablespace tablespace_name datafile ‘表空间文件路径’ size 1G autoextend on next 100M maxsize unlimited;
create tablespace:创建表空间关键字
tablespace_name:表空间名称
datafile:指定表空间文件(一般指向oracle安装根目录下oradata/数据库实例名/.dbf)
size 1G:指定表空间文件的初始大小,大小单位可以是G、M、K等
autoextend on next 100M:autoextend表示表空间大小自动扩展,on next 100M指定每次表空间满了之间扩展的大小
maxsize unlimited:maxsize指定表空间的最大存储值,unlimited表示不限制表空间的最大值(也就是只要硬盘不满,表空间就可以一直扩展)
–创建一个test1的表空间(必须使用管理员用户system, sys )
create tablespace test1 datafile ‘D:\app\Administrator\oradata\orcl\test1data.dbf’ size 1G
autoextend on next 100M maxsize unlimited;
–修改表空间
ALTER DATABASE DATAFILE ‘D:\app\Administrator\oradata\orcl\test1data.dbf’ AUTOEXTEND ON NEXT 200M MAXSIZE 2G
–修改原有的数据文件大小
alter database datafile ‘D:\app\Administrator\oradata\orcl\test1data.dbf’ resize 100M;
–为表空间增加新的数据文件
alter tablespace 表空间名 add datafile 数据文件 size 大小;
–删除表空间
drop tablespace表空间名;
创建临时表空间
当排序不能在分配的空间中完成时,就会使用磁盘排序的方式,即在Oracle实例中的临时表空间中进行。
–创建临时表空间语法:
create temporary tablespace tablespace_name tempfile ‘表空间文件路径’ size 1G autoextend on next 100M maxsize unlimited;
temporary:表明创建的表空间是临时表空间
tempfile:指定临时表空间文件
–创建临时表空间(用管理员用户)
create temporary tablespace test1temp
tempfile ‘D:\app\Administrator\oradata\orcl\test1temp.dbf’
size 1G autoextend on next 100M maxsize unlimited;
创建用户
–创建用户语法:
create user user_name default tablespace tablespace_name temporary tablespace temptablespace_name identified by password;
create user:创建用户关键字
user_name:用户名
default tablespace tablespace_name:指定用户的默认表空间,tablesapce_name:表空间名(如果省略默认使用users表空间)
temporary tablespace temptablespace_name:指定用户的默认临时表空间,temptablespace_name临时表空间名(如果省略默认使用temp表空间)
identified by password:identified by 指定用户的密码,password用户密码
–创建一个test1用户
create user test1 default tablespace test1 temporary tablespace test1temp identified by test1;
–修改用户
alter user user_name default tablespace tablespace_name temporary tablespace temptablespace_name identified by password;
–删除用户
drop user 用户名;
原文链接:https://blog.csdn.net/tcz_666/article/details/133152270