表空間
創建表空間: create tablespace 表空間名 datafile ‘數據庫存放地址/數據文件名’ size 5M
擴充表空間: alter tablespace 表空間 add datafile ‘數據庫存放地址/數據文件名’ size 10M
刪除表空間:drop tablespace 表空間名 including contents and datafiles
臨時表空間 temporary tablespace 用於排序 oracle創建數據庫時候自帶的
- temptabs:安裝ERP產品的時候由DBA創建的作用是用來存放ERP使用過程中生產的臨時表‘大家口頭的臨時表空間’
原則
- 表空間的所有操作,需要使用數據庫指令,而不是操作系統指令
- 數據文件 只能增加,不能減少
- 通常情況下,表空間只增大不減小
- 表空間對應文件
單獨的一個數據文件最大不超過32G
最小存儲單元8k
用戶
- 創建用戶:create user 用戶名 identified by 密碼 default tablespace 表空間名 temporary tablespace temp
- 賦予/移除權限:grant(revoke) connect,resource to 用戶名;
- 刪除用戶:drop user 用戶名 cascade;
表
- 創建表:create table 表名
- 仿照表結構創臨時表 create table 表名 as select * from 表名 where 1=2 (主鍵和索引不能被複制)
- 查看錶結構:desc 表名
- 增刪改需要commit
- select * from 表名 where 字段 is null;
- sqlplus快捷鍵 ‘/’, ‘ed’
- exist 和 in
- 如果出現欄位和函數,就要用group by
- truncate 高水位 臨時表刪除數據
- merge
索引
- 大大增加select效率,降低insert,update效率
- create index 索引名 on 表名(欄位,欄位…)
- drop index 索引名
備份還原
- exp/imp ——T產品默認方式
- 優點:語法簡單,使用簡單
- 缺點:速度慢,一天備份一次
- expdb/impdb
- 優點:語法簡單,速度比exp/imp塊
- 缺點:只能在服務器執行,一天備份一次
rman
- 優點:速度快,實時備份,可以還原到之前任意時間點
- 缺點:語法複雜,維護複雜,還原測試複雜
備份例句
- exp 語法關鍵字
- file 導出備份生成的文件名
- owner 對象所屬用戶
buffer 緩存
exp system/tiptop100@test file=exp_all.dmp tables=a,b buffer=400000 log=exp_ab.log
還原例句
- imp 語法關鍵字
- file 所用備份文件
- ignore 忽略錯誤
log 日誌對象
imp test/test@test file=exp_all.dmp tables=a,b buffer=400000 log=exp_ab.log
換種方式
vi my.txt userid=test/test@test file=exp_all.dmp tables=a.b buffer=400000 log=exp_ab.log exp parfile=my.txt