oracle删除用户的所有表

转自https://www.cnblogs.com/chshnan/archive/2012/02/07/2341694.html

1、查看当前登录的用户的所有表:

select table_name from user_tables;

查看除了以 SYM_ 开头的所有表:

select table_name from user_tables where table_name NOT LIKE 'SYM_%';

如果有删除用户的权限,则可以:

drop user user_name cascade;
eg:
drop user SIMON cascade;
drop user TEST cascade;
#加了cascade就可以把用户连带的数据全部删掉

删除后再创建该用户。--创建管理员用户

create user 用户名 identified by 密码 default tablespace space_data(表空间名称) temporary tablespace space_temp(临时表空间名称);
eg:
create user SIMON identified by "123456"
default tablespace SIMON_DATA 
temporary tablespace SIMON_TEMP;

create user TEST identified by "123456"
default tablespace TEST_DATA 
temporary tablespace TEST_TEMP;
--授权 grant connect,resource,dba to 用户名;
eg:
grant connect,resource,dba to TEST;
--修改限额 ALTER USER "用户名" QUOTA UNLIMITED ON SPACE_DATA(表空间名称); --查看所有用户对象 select uo.object_name,uo.object_type from user_objects uo where uo.object_type<>'LOB' order by uo.object_type desc;

2、如果没有删除用户的权限,则可以执行:

select 'drop table '||table_name||';'
from cat
where table_type='TABLE';
# 将会输出一批删除表的sql语句,这些SQL语句执行一下就可以了。(需要有drop table的权限)
select 'drop table '||table_name||';'
from cat
where table_type='TABLE' 
and table_name LIKE 'SYM_%';
# 删除表名以SYM开头的表
select 'drop table '||table_name||';'
from cat
where table_type='TABLE' 
and table_name LIKE '%TRIGGER';
# 删除表名以TRIGGER结尾的

创建表空间的方式创建用户

 

/*第1步:创建临时数据表空间  */
create temporary tablespace SIMON_TEMP
tempfile 'C:\simon\user_temp.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;

/*第2步:创建数据表空间  */
create tablespace SIMON_DATA  
logging  
datafile 'C:\simon\user_data.dbf'
size 50m  
autoextend on  
next 50m maxsize 20480m  
extent management local; 

/*第3步:创建用户并指定表空间  */
create user simon identified by "123456"
default tablespace SIMON_DATA  
temporary tablespace SIMON_TEMP;

/*第4步:给用户授予权限  */
grant connect,resource,dba to simon;
commit;
posted @ 2020-05-14 17:02  士官长  阅读(1042)  评论(0编辑  收藏  举报