首先我們要弄明白Oracle數(shù)據(jù)庫的整個操作流程,如下圖所示。
接下來對表空間以及用戶的各項操作介紹都是需要建立在以下三步的基礎(chǔ)上:
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:國際域名空間、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、長安網(wǎng)站維護(hù)、網(wǎng)站推廣。
第1步:使用cmd命令打開DOS窗口。
第2步:輸入命令: sqlplus /nolog ,進(jìn)入oracle控制臺。
第3步:輸入conn 用戶名/密碼 sysdba 以DBA角色進(jìn)入,提示連接成功。(注:此處用戶必須有dba權(quán)限,如:sys)
備注:在操作過程中可以使用
clear SCR進(jìn)行清屏
create tablespace dweb logging datafile 'C:\Program Files\Oracle\Inventory\dweb.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;1234567
drop tablespace ackj including contents and datafiles;1
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
在實際操作中,一般一個用戶負(fù)責(zé)對應(yīng)一個表空間,因此在創(chuàng)建用戶的同時,需要賦予其所屬表空間。
create user dweb identified by dweb default tablespace dweb;1
drop user dweb cascade;1
alter user dweb identified by 123456;1
select username from dba_users;select * from all_users;12
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
--查看用戶所屬的表空間(用戶名必須大寫)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';--獲取當(dāng)前用戶下所有的表select table_name from user_tables;--刪除某用戶下所有的表數(shù)據(jù)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查出數(shù)據(jù)庫中所以外鍵的約束名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啟用外鍵和觸發(fā)器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;
文章題目:Oracle操作用戶和表空間的總結(jié)
文章來源:http://www.yijiale78.com/article8/pcpgip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、網(wǎng)站收錄、移動網(wǎng)站建設(shè)、商城網(wǎng)站、網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)