删除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;