Oracle操作用户和表空间的总结
admin
2023-02-07 17:00:04
0

1. Oracle数据库的操作流程

首先我们要弄明白Oracle数据库的整个操作流程,如下图所示。 
Oracle操作用户和表空间的总结 
接下来对表空间以及用户的各项操作介绍都是需要建立在以下三步的基础上:

  • 第1步:使用cmd命令打开DOS窗口。

  • 第2步:输入命令: sqlplus /nolog ,进入oracle控制台。

  • 第3步:输入conn 用户名/密码 sysdba 以DBA角色进入,提示连接成功。(注:此处用户必须有dba权限,如:sys)

  • 备注:在操作过程中可以使用clear SCR进行清屏

2. 操作表空间

2.1 创建表空间

create tablespace dweb
logging 
datafile 'C:\Program Files\Oracle\Inventory\dweb.dbf' size 50m 
autoextend on next 50m maxsize 20480m 
extent management local;1234567

2.2 删除表空间

drop tablespace ackj including contents and datafiles;1

2.3 查看表空间使用

SELECT  a.tablespace_name 表空间名
       ,total 表空间大小
       ,free 表空间剩余大小
       ,(total-free) 表空间使用大小
       ,(total/(1024*1024*1024)) as 表空间大小G
       ,free / (1024 * 1024 * 1024) 表空间剩余大小G
       ,(total - free) / (1024 * 1024 * 1024) 表空间使用大小G
       ,round((total - free) / total, 4) * 100 使用率  FROM (SELECT tablespace_name, SUM(bytes) free          FROM dba_free_space         GROUP BY tablespace_name) a,
       (SELECT tablespace_name, SUM(bytes) total          FROM dba_data_files         GROUP BY tablespace_name) b WHERE a.tablespace_name = b.tablespace_name;123456789101112131415

3. 操作用户

3.1 创建用户

在实际操作中,一般一个用户负责对应一个表空间,因此在创建用户的同时,需要赋予其所属表空间。

create user dweb identified by dweb default tablespace dweb;1

3.2 删除用户

drop user dweb cascade;1

3.3 修改密码

alter user dweb identified by 123456;1

3.4 查看用户列表

select username from dba_users;select * from all_users;12

4. 用户授权

4.1 权限说明

4.2 用户授权

grant connect,resource,dba to dweb;grant create any sequence to dweb;grant create any table to dweb;grant delete any table to dweb;grant insert any table to dweb;grant select any table to dweb;grant unlimited tablespace to dweb;grant execute any procedure to dweb;grant update any table to dweb;grant create any view to dweb;12345678910

5. 相关操作

--查看用户所属的表空间(用户名必须大写)select username,default_tablespace from dba_users where username='DWEB';--查看用户具有的表空间(用户名必须大写)select * from dba_sys_privs where grantee='DWEB';--Oracle删除指定用户所有表的方法(用户名必须大写)select 'Drop table '||table_name||';' from all_tableswhere owner='DWEB';--获取当前用户下所有的表select table_name from user_tables;--删除某用户下所有的表数据select 'truncate table  ' || table_name from user_tables;--启用外键约束的命令alter table table_name enable constraint constraint_name; --禁用外键约束的命令alter table table_name disable constraint constraint_name;--用SQL查出数据库中所以外键的约束名select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R';select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R';12345678910111213141516171819202122232425
--ORACLE启用外键和触发器SET SERVEROUTPUT ON SIZE 1000000BEGINfor c in (select 'ALTER TABLE '||TABLE_NAME||' ENABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);begin
 EXECUTE IMMEDIATE c.v_sql;
 exception when others then
 dbms_output.put_line(sqlerrm); end;end loop; for c in (select 'ALTER TABLE '||TNAME||' ENABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
 dbms_output.put_line(c.v_sql);
 begin
 execute immediate c.v_sql;exception when others then
 dbms_output.put_line(sqlerrm); end;end loop;end;/ 
commit;12345678910111213141516171819202122
--禁用脚本SET SERVEROUTPUT ON SIZE 1000000BEGINfor c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);begin
 EXECUTE IMMEDIATE c.v_sql;
 exception when others then
 dbms_output.put_line(sqlerrm); end;end loop; for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
 dbms_output.put_line(c.v_sql);
 begin
 execute immediate c.v_sql;exception when others then
 dbms_output.put_line(sqlerrm); end;
 end loop;
 end;
 / commit;


相关内容

热门资讯

工业和信息化部:依托标准牵引智... 日前,在北京举办的《人工智能 智能体互联》系列标准应用推进专题会上,工业和信息化部科技司副司长甘小斌...
原创 强... 进入下半年,子系品牌新一轮旗舰和中端性能机开始密集预热,近期更是有博主连续放出两条关键信息,分别指向...
“文学超界面”探索数字时代人文... 来源:新华网 当严肃文学的深厚内核遇见人工智能生成内容(AIGC)的影像创造力,会碰撞出怎样的火花...
以防长称已为应对伊朗局势做好“... △以色列国防部长卡茨(资料图)当地时间23日,据以色列方面消息,以色列国防部长卡茨当天表示,鉴于当前...
美参议院否决限制特朗普对伊战争... △美国国会(资料图)当地时间23日,美国参议院以49票对47票的表决结果,否决了旨在限制特朗普对伊朗...
工信部部长:搞“脱钩断链”对谁... 7月23日,2026年亚太经合组织(APEC)数字和人工智能部长会议新闻发布会在成都召开。会议主席、...
AMD展示最强AI加速器MI4... IT之家 7 月 24 日消息,今天(7 月 24 日)在美国旧金山召开的年度盛会 Advancin...
河北:知行研学度盛夏 多彩实践... 冀时新闻报道暑假期间,我省各地推出形式多样的青少年研学活动,让孩子们在实践中增长见识、锤炼品格,度过...
世界互联网大会数智健康工作组以... 7月22日,2026年世界互联网大会数字丝路发展论坛在陕西西安开幕。这是世界互联网大会连续第三年举办...
开立医疗获得实用新型专利授权:... 证券之星消息,根据天眼查APP数据显示开立医疗(300633)新获得一项实用新型专利授权,专利名为“...