-- 设置表空间超载时自动增长: -- 表空间将满时会自动增加256m大小空间: alter database datafile 'D:\oracle\oradata\tablespace_name.dbf' autoextend on next 256m; -- 表空间每次增加256M,累计增加到1024M后将不再增加: alter database datafile 'D:\oracle\oradata\tablespace_name.dbf' autoextend on next 256m maxsize 1024m;
-- 创建用户(指定默认表空间,所以要先创建表空间): createuser username identified by passwd default tablespace tablespace_name temporary tablespace temp; -- 授予用户权限: grant dba,connect,resource to username; -- 修改用户密码(处于锁定状态的用户需先解锁): alteruser username identified by new_passwd; -- 解锁用户: alteruser username account unlock;
-- 删除用户: dropuser username cascade; -- 删除表空间: -- 删除空表空间,不包含物理文件 drop tablespace tablespace_name; -- tablespace_name不加.dbf后缀哦!!! -- 删除空表空间,包含物理文件 drop tablespace tablespace_name including datafiles; -- 删除空(非空)表空间,不包含物理文件 drop tablespace tablespace_name including contents; -- 删除空(非空)表空间,包含物理文件 drop tablespace tablespace_name including contents and datafiles; -- 如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
-- including 说明 including contents -- 删除表空间及对象; including contents and datafiles -- 删除表空间、对象及物理文件(数据文件tablespace_name.dbf); including contents CASCADE CONSTRAINT-- 删除关联;
最终脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
-- 创建表空间和用户 --创建表空间 Linux createtablespace mars_data datafile '/u01/app/oracle/oradata/orcl/mars_data.dbf' size 256m; --创建表空间 Windows createtablespace mars_data datafile 'F:/oracle19c/oradata/ORCL/orclpdb/mars_data.dbf' size 256m; --表空间将满时会自动增加256m大小空间 alter database datafile 'F:/oracle19c/oradata/ORCL/orclpdb/mars_data.dbf' autoextend on next 256m; --创建用户,指定默认表空间 createuser mars identified by123456789default tablespace mars_data temporary tablespace temp; --授予用户权限 grant dba,connect,resource to mars;
-- 删除用户和表空间 --删除用户 dropuser mars cascade; --删除空(非空)表空间,包含物理文件 drop tablespace mars_data including contents and datafiles;