本帖最后由 da11 于 2023-8-8 01:15 编辑
ORACLE12C PDB创建默认表空间和用户语句及删除对应表空间和用户的方法
1.进入服务器,使用dba进入数据库
sqlplus sys/tiger as sysdba
2.pdb数据库,要先跳转至对应的pdb
SQL>alter session set container=pdborcl;
3.创建临时表空间和数据表空间:
创建临时表空间
SQL>create temporary tablespace testtemptablespace tempfile '/data/oracle/datafile/testtemptablespace.dbf' size 500M autoextend on next 100M;
创建数据表空间
SQL>create tablespace testtablespace datafile '/data/oracle/datafile/testtablespace.dbf' size 500M autoextend on next 100M;
#注意:数据文件 dbf 对应路径应统一存放,使用 select name from v$datafile; 命令查看统一存放的路径
# size 500M 为表空间大小
#autoextend on next 100M; 为扩容大小单位
4.创建用户及授权表空间权限:
SQL>CREATE USER 用户名 IDENTIFIED BY 密码 DEFAULT tablespace 数据表空间 TEMPORARY tablespace 临时表空间;
5.用户授权:
grant connect,resource to testuser ;
grant create any sequence to testuser ;
grant create any table to testuser ;
grant delete any table to testuser ;
grant insert any table to testuser ;
grant select any table to testuser ;
grant unlimited tablespace to testuser ;
grant execute any procedure to testuser ;
grant update any table to testuser ;
grant create any view to testuser ;
或者直接授权dba权限
grant dba to testuser ;
删除表空间、用户
1. 删除表空间
-- 删除空的表空间,但是不包含物理文件
DROP tablespace 表空间名称;
-- 删除空表空间,包含物理文件
DROP tablespace 表空间名称 INCLUDING datafiles;
-- 删除非空表空间,但是不包含物理文件
DROP tablespace 表空间名称 INCLUDING contents;
--删除非空表空间,包含物理文件
DROP tablespace 表空间名称 INCLUDING contents AND datafiles;
--如果其他表空间中的表有外键等约束关联到了本表空间中表的字段,需要加上CASCADE CONSTRAINTS
DROP tablespace 表空间名称 INCLUDING contents AND datafiles CASCADE CONSTRAINTS;
2. 删除用户
-- 只是删除此用户
DROPUSER 用户名;
-- 会删除此用户及此用户关联的所有表和视图
DROPUSER 用户名 CASCADE;
|