删除Oracle用户及表空间

删除Oracle用户及表空间

--以sysdba用户登录,查找需要删除的用户
conn / as sysdba

--查找用户
select * from dba_users;
select username from dba_users;
select username from dba_users where username='JACK';
select username from all_users where username='JACK';

--查看所有表空间总大小、已使用大小、剩余大小
select a.tablespace_name,total "Total(M)",free "Free(M)",total-free "Used(M)",round(((total-free)/total)*100,2) "Used(%)" from 
( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files
   group by tablespace_name) a, 
( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space
   group by tablespace_name) b
where a.tablespace_name=b.tablespace_name;

--查找表空间存储文件的路径
select * from dba_data_files; 

--查看所有表占用的表空间的大小
select t.segment_name, t.segment_type, sum(t.bytes / 1024 / 1024) "占用空间(M)"
from dba_segments t
where t.segment_type='TABLE'
group by OWNER, t.segment_name, t.segment_type;

--查看表所属的用户
select owner,table_name from dba_tables where table_name='TEST_TBL01';

--查看用户所在的表空间(查看当前用户的缺省表空间)
conn JACK
select username,default_tablespace from user_users;

--查看表所属的表空间(查看所有表)
select table_name,tablespace_name from user_tables;

--查看表所属的表空间(查看指定表)
select table_name,tablespace_name from user_tables where table_name=upper('&table_name'); 

--删除用户
--注意:指定 cascade 会删除用户下的所有对象(包括表、视图、主键、外键、索引等;但不会删除存储过程、函数、包)。如果不指定则仅仅只删除用户,一般建议指定
conn /as sysdba 
drop user myusername cascade;

--删除表空间
drop tablespace mytablespace including contents and datafiles cascade constraint;

例如:删除用户JACK及表空间USER_DATA:
--删除用户JACK,级联删除
drop user JACK cascade;
--删除表空间,及对应的表空间文件也删除掉。注意:如果多个用户使用相同的表空间,删除用户时不要删除表空间
drop tablespace USER_DATA including contents and datafiles cascade constraint;

 

  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值