Oracle常见用法总结
近來,操作數(shù)據(jù)庫比較多,總結(jié)了一下常用的語句!!!
(1)Oracle的默認(rèn)用戶
用戶名:scott? ? ? 密碼: tiger? ? ? ? ? ? ? ? ? 權(quán)限:普通用戶 用戶名:sys? ? ? ? 密碼: change_on_install? 權(quán)限:系統(tǒng)管理員 用戶名:system? 密碼: manager? ? ? ? ? ? ? ??權(quán)限:本地管理員若直接用 sqlplus sys/change_on_install 登錄不成功,可更改為sqlplus sys as sysdba/change_on_install
(2)創(chuàng)建表空間
--創(chuàng)建永久表空間 create tablespace tablename--表空間名稱 datafile '路徑+文件名.dbf' --文件路徑及文件名 size 20480M --表空間大小 AUTOEXTEND ON NEXT 500M --每次自動(dòng)擴(kuò)展500M --創(chuàng)建臨時(shí)表空間 create temporary tablespace tablename tempfile '路徑+文件名.dbf' size 500M(3)擴(kuò)充表空間
alter tablespace tablename add datafile '路徑+文件名.DBF' size 20000M autoextend on next 500M maxsize unlimited;(4)臨時(shí)更改表空間大小
ALTER TABLESPACE tablename ADD TEMPFILE '路徑+文件名.dbf' size 20000M autoextend on next 50M maxsize unlimited;(5)刪除表空間
--刪除空的表空間,但是不包含物理文件 drop tablespace tablespace_name; --刪除非空表空間,但是不包含物理文件 drop tablespace tablespace_name including contents; --刪除空表空間,包含物理文件 drop tablespace tablespace_name including datafiles; --刪除非空表空間,包含物理文件 drop tablespace tablespace_name including contents and datafiles; --如果其他表空間中的表有外鍵等約束關(guān)聯(lián)到了本表空間中的表的字段,就要加上CASCADE CONSTRAINTS drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;參考:https://blog.csdn.net/gbj890229/article/details/6623996
(6)創(chuàng)建用戶
--創(chuàng)建用戶 create user username identified by password default tablespace tablename;(7)刪除用戶
--刪除用戶 drop user username cascade;(8)刪除表空間
#刪除表空間 drop tablespace tablename including contents and datafiles;(9)給用戶授權(quán)
DBA:擁有全部特權(quán),是系統(tǒng)最高權(quán)限,只有DBA才可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。
RESOURCE:擁有Resource權(quán)限的用戶只可以創(chuàng)建實(shí)體,不可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。
CONNECT:擁有Connect權(quán)限的用戶只可以登錄Oracle,不可以創(chuàng)建實(shí)體,不可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。
對于普通用戶:授予connect, resource權(quán)限。
對于DBA管理用戶:授予connect,resource, dba權(quán)限。
grant connect,resource to username;(10)imp導(dǎo)入sql文件
imp username/password file=路徑+文件名.sql full=y(11)查詢表空間大小
selecta.a1 表空間名稱,c.c2 類型,c.c3 區(qū)管理,b.b2/1024/1024 表空間大小M,(b.b2-a.a2)/1024/1024 已使用M,substr((b.b2-a.a2)/b.b2*100,1,5) 利用率from(select tablespace_name a1, sum(nvl(bytes,0)) a2 from dba_free_space group by tablespace_name) a,(select tablespace_name b1,sum(bytes) b2 from dba_data_files group by tablespace_name) b,(select tablespace_name c1,contents c2,extent_management c3 from dba_tablespaces) cwhere a.a1=b.b1 and c.c1=b.b1;(12)查找某個(gè)字段所在的表名
--查找當(dāng)前用戶下某個(gè)字段所屬的表 select *from user_tab_columns twhere t.COLUMN_NAME = 'CONS_ID';?
總結(jié)
以上是生活随笔為你收集整理的Oracle常见用法总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用BMfont制作含有中文图片的.fn
- 下一篇: 数字孪生网络(DTN)架构