Oracle常见用法总结
生活随笔
收集整理的這篇文章主要介紹了
Oracle常见用法总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
近來,操作數據庫比較多,總結了一下常用的語句!!!
(1)Oracle的默認用戶
用戶名:scott? ? ? 密碼: tiger? ? ? ? ? ? ? ? ? 權限:普通用戶 用戶名:sys? ? ? ? 密碼: change_on_install? 權限:系統管理員 用戶名:system? 密碼: manager? ? ? ? ? ? ? ??權限:本地管理員若直接用 sqlplus sys/change_on_install 登錄不成功,可更改為sqlplus sys as sysdba/change_on_install
(2)創建表空間
--創建永久表空間 create tablespace tablename--表空間名稱 datafile '路徑+文件名.dbf' --文件路徑及文件名 size 20480M --表空間大小 AUTOEXTEND ON NEXT 500M --每次自動擴展500M --創建臨時表空間 create temporary tablespace tablename tempfile '路徑+文件名.dbf' size 500M(3)擴充表空間
alter tablespace tablename add datafile '路徑+文件名.DBF' size 20000M autoextend on next 500M maxsize unlimited;(4)臨時更改表空間大小
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; --如果其他表空間中的表有外鍵等約束關聯到了本表空間中的表的字段,就要加上CASCADE CONSTRAINTS drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;參考:https://blog.csdn.net/gbj890229/article/details/6623996
(6)創建用戶
--創建用戶 create user username identified by password default tablespace tablename;(7)刪除用戶
--刪除用戶 drop user username cascade;(8)刪除表空間
#刪除表空間 drop tablespace tablename including contents and datafiles;(9)給用戶授權
DBA:擁有全部特權,是系統最高權限,只有DBA才可以創建數據庫結構。
RESOURCE:擁有Resource權限的用戶只可以創建實體,不可以創建數據庫結構。
CONNECT:擁有Connect權限的用戶只可以登錄Oracle,不可以創建實體,不可以創建數據庫結構。
對于普通用戶:授予connect, resource權限。
對于DBA管理用戶:授予connect,resource, dba權限。
grant connect,resource to username;(10)imp導入sql文件
imp username/password file=路徑+文件名.sql full=y(11)查詢表空間大小
selecta.a1 表空間名稱,c.c2 類型,c.c3 區管理,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)查找某個字段所在的表名
--查找當前用戶下某個字段所屬的表 select *from user_tab_columns twhere t.COLUMN_NAME = 'CONS_ID';?
總結
以上是生活随笔為你收集整理的Oracle常见用法总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用BMfont制作含有中文图片的.fn
- 下一篇: 数字孪生网络(DTN)架构