一、dba_tablespaces和user_tablespaces两个数据字典
1、dba_tablespaces:记录的是具有管理员权限的用户的表空间,需要登录具有管理员权限的用户才能访问:desc dba_tablespaces
2、user_tablespaces:记录的是普通用户的表空间,权限大于等于普通用户都可以访问:desc user_tablespaces
二、dba_users和user_users两个数据字典
1、dba_users:记录的是用户的信息,需要登录具有管理员权限的用户才能访问:desc dba_users
2、user_users:权限大于等于普通用户都可以访问:desc user_users
三、dba_tables和user_tables两个数据字典
四、dba_constraints和user_constraints两个数据字典
五、设置用户的默认或者临时表空间,默认表空间也是永久表空间
alert user username default | temporary tablespace tablespace_name
需要注意的是普通用户没有修改默认表空间和临时表空间的权限,需要赋予权限或者使用具有管理员权限的用户来为普通用户设置默认表空间和临时表空间
六、创建表空间
create [ temporary ] tablespace tablespace_name tempfile | datafile ' xxx.dbf ' size xx
eg: create tablespace test1 datafile 'test1.dbf' size 10m;
create temporary tablespace temp1 tempfile 'temp1.dbf' size 5m;
如果不加temporary则表示创建永久表空间
七、dba_data_files和dba_temp_files 数据字典
dba_data_files存储的是永久表空间数据文件( .dbf文件 )的信息: select file_name from dba_data_files where tablespace_name='TEST1';
dba_temp_files存储的是临时表空间数据文件的信息: select file_name from dba_temp_files where tablespace_name='TEMP1';
注意:tablespace_name后面引号中要大写
八、修改表空间
1、修改表空间的状态
①、 修改表空间的联机或脱机状态(默认是联机状态):alter tablespace tablespace_name online | offline;
②、设置表空间只读或可读写状态(默认是可读写状态,并且前提是处于联机状态):
alter tablespace tablespace_name read only | read write;
alter tablespace test1 read only;
2、查看表空间的状态:
select status from dba_tablespaces where tablespace_name='TEST1';
3、修改表空间的数据文件
①、向表空间中添加数据文件:
alter tablespace tablespace_name add datafile | tempfile 'xxx.dbf' size xx;
②、删除数据文件(不能删除第一个创建的数据文件,如果要删除第一个数据文件,则需要删除表空间)
alter tablespace tablespace_name drop datafile | tempfile 'xxx.dbf';
4、删除表空间(如果不加 including contents 则删除表空间的时候不会删除数据文件,加上则会删除数据文件):
drop tablespace tablespace_name [ including contents ]