oracle 用户与表空间

表空间概念详解
1.使用系统用户登录SQL Plus:
sys,system;sysman;scott
用户登录格式:[username/password] [@server] [as sysdba|sysoper]
                        system/orcl @orcl as sysdba 

                        备注:orcl 就是自己设置的服务名system/orcl

如果已经使用某个用户登录了SQL Plus,切换登录用户:
                        connect sys/orcl as sysdba 

                        备注:书写不区分大小写

2. 查看登录用户
show user 

备注:sqlplus 中输入的命令不需要分号,当输入的是sql语句时需要加分号

通过”数据字典”—dba_users(数据库提供的表,也是由很多的字段组成)查看用户的其他字段信息
查看数据字典中的字段:

desc dba_users
通过数据字典查看有多少个用户:

select username from dba_users;
3. 启用(scott)用户的语句:
使用scott用户登录sqlplus:(scott用户的默认密码是tiger)
connect scott/tiger
4. 表空间概述:
表空间:

        数据库的逻辑存储空间,可以理解为在数据库中开辟的空间用来存储数据库对象;

表空间和数据文件的关系:

        表空间由一个或多个数据文件组成;数据文件的大小和位置可以自己定义;

表空间的分类:
    永久表空间:数据库中要永久化存储的一些对象,如:表、视图、存储过程
    临时表空间:数据库操作当中中间执行的过程,执行结束后,存放的内容会被自动释放
    UNDO表空间:用于保存事务所修改数据的旧值,可以进行数据的回滚
5. 查看用户的表空间:
①数据字典

dba_tablespaces(系统管理员级别查看的数据字典)

user_tablespaces(普通用户查看的数据字典)

②.查看表空间的字段
desc dba_tablespaces
③.查看有几个表空间
select tablespace_name from dba_tablespaces;
⑤.查看用户的字段信息
desc dba_users
⑥.查看用户的默认表空间、临时表空间等等
select default_tablespace from dba_users where username=’SYS’;
6. 设置用户的默认或临时表空间
alter user username default|tempporart tablespace tablespace_name;
 备注:普通用户没有设置表空间的权限
7. 创建、修改、删除表空间
①.创建表空间
create [temporary] tablespace tablespace_name tempfile|datafile ‘xx.dbf’ size xx;
备注:如果创建的是临时表空间,需要加上temporary关键字;
②.查看表空间的具体路径:(通过dba_data_files 和 dba_temp_files这个数据字典)
desc dba_data_files
select file_name from dba_data_files where tablespace_name=”;(条件是表空间的名字,需要大写)
③.修改表空间的状态
设置联机或脱机的状态(表空间是脱机时不可用,默认是联机的)
alter tablespace tablespace_name online|offline;
如何知道表空间所处的状态?(通过这个dba_tablespaces数据字典)
desc dba_tablespaces
select status from dba_tablespaces where tablespace_name=”;(条件是表空间的名字,需要大写)
设置只读或可读写的状态(只有在联机状态才可以更改,默认的联机状态就是读写状态)
alter tablespace tablespace_name read only | read write;
④.修改数据文件
增加数据文件
alter tablespace tablespace_name add datafile ‘xx.dbf’ size xx;
select file_name from dba_data_files where tablespace_name=”;(条件是表空间的名字,需要大写)
备注:通过这条select语句就查询到当前表空间中的数据文件
删除数据文件(不能删除表空间当中第一个数据文件,如果要删除就需要删除整个表空间)
alter tablespace tablespace_name drop datafile ‘xx.dbf’;
⑤.删除表空间
drop tablespace tablespace_name[including contents];
备注:如果只是删除表空间不删除该表空间下的数据文件,则不加including contents;
 
---------------------
作者:疯狂的咸鸭蛋
来源:CSDN
原文:https://blog.csdn.net/guo_cw/article/details/80530726
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自www.cnblogs.com/xiaohuizhenyoucai/p/11101547.html