您的位置:首页 > 数据库 > Oracle

oracle基本操作

2019-08-17 21:05 1511 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/qq_38325614/article/details/99696225

1.用户和表空间

  • 查看当前用户
show user;
  • 锁定/解锁用户 (lock:锁定/unlock:解锁)
alter user 'username' account lock/unlock;
  • 查看用户表空间 (查看系统用户表空间将user_tablespaces换为dba_tablespaces)
select tablespace_name from user_tablespaces;
  • 创建表空间
create tablespace tablespace_name datafile 'test1_tablespace.dbf' size 10m;
  • 创建临时表空间
create temporary tablespace tablespace_name tempfile 'temptest1_tablespace.dbf' size 10m;
  • 查看表空间存放位置
select file_name from dba_data_files where tablespace_name = 'tablespace_name';
  • 查看临时表空间存放位置
select file_name from dba_temp_files where tablespace_name = 'tablespace_name';
  • 查看用户使用的默认表空间和临时表空间
select default_tablespace,temporary_tablespace from dba_users where username = 'username';
  • 更改用户默认表空间
alter user username default tablespace tablespace_name;
  • 修改表空间的状态(online:联机/offline:脱机)
alter tablespace tablespace_name online/offline;
  • 查看表空间的状态
select status from dba_tablespace where tablespace_name = 'TABLESPACE_NAME';
  • 设置表空间只读/可读写 (默认是可读写,表空间必须是联机状态才能设置)
alter tablespace tablespace_name read only/read write
  • 添加表空间的数据文件
alter tablespace tablespace_name add datafile 'filename.dbf' size 5m;
  • 删除表空间的数据文件(不可以删除创建表空间时创建的数据文件,如果要删除需要将整个表空间删除)
alter tablespace tablespace_name drop datafile 'filename.dbf';
  • 删除表空间 (如果要删除数据文件在末尾加上 including contents)
drop tablespace tablespace_name [including contents];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: