標籤:
crud 增刪改查 create read update delete
1--oracle資料庫的安裝
系統預設建立兩個使用者 sys和system 密碼自訂
超級管理員:sys
管理員:system
密碼:5615
2--啟動資料庫的服務
service
listener
3--訪問資料庫
使用oracle內建的用戶端工具sqlplus(前提條件:在path中添加D:\oracle\app\oracle\product\11.2.0\server\bin)
wind+R鍵開啟運行視窗
輸入:sqlplus 斷行符號
提示要求輸入使用者名稱和密碼
sys和密碼 不能直接登入資料庫
system和密碼 可以直接登入資料庫 說明:這種方式只能以普通使用者身份登入
如果要以sys登入資料庫
wind+R鍵 輸入 sqlplus sys/5615 as sysdba; 斷行符號
查看目前使用者的登入名稱
show user; 斷行符號
4--啟動與關閉資料庫
關閉資料庫:
shutdown immediate;
啟動資料庫:
startup open;
sys可以啟動和關閉資料庫
system 沒有這個許可權
5--資料庫使用者的操作
sys建立使用者:
create user owen identified by 123;
使用者建立之後預設情況是被鎖住的,並且是沒有分配角色的,需要對使用者解鎖
alter user owen account unlock;
sys為使用者指派角色
grant connect to owen;
此時就可以使用owen使用者登入資料庫,但是只有登入的許可權
conn owen/123;
sys為使用者指派resource角色
grant resource to owen;
這時就可以在當前owen使用者下進行對象操作
create table owen_record (login_time varchar(19));
如果需要將某個使用者變為超級管理員
grant sysdba to owen;
刪除使用者
drop user owen;
刪除使用者(將使用者所建立的所有對象全部刪除)
drop user owen cascade;
從owen使用者身上回收sysdba角色
revoke sysdba from owen;
查詢目前使用者角色下的所有表名稱
select table_name from user_tables;
------------------------------------------------------------------------------------------------------------------------------
資料表空間table space
是oracle資料庫中最大的邏輯結構
從邏輯上,oracle資料庫是由若干個資料表空間組成的
資料表空間與資料庫的物理結構上有著十分密切的關係,他與磁碟上若干個資料檔案相對應
從物理上說資料庫的資料被存放在資料檔案中,從邏輯上說資料是被存放在資料表空間中
一個資料檔案只能屬於一個資料表空間,一個資料表空間可以有多個資料檔案
oracle資料把方案對象(表、索引、視圖、序列)邏輯的儲存在資料表空間中
|--資料表空間1
|--資料表空間2
|--資料表空間3
|--資料檔案1
|--資料檔案2
|--磁碟1
|--資料檔案3
|--磁碟2
|--資料檔案4
|--磁碟2
建立暫存資料表空間
create temporary tablespace------建立資料表空間檔案的關鍵字
owen_temp------資料表空間名稱
tempfile ‘D:\oracle\user\owen_temp.dbf‘------該路徑一定真實存在
size 100m------初始大小
autoextend on------開啟自動擴充
next 10m maxsize 1000m------每次擴充的大小和最大空間
建立資料資料表空間檔案語句
create tablespace
owen_data
datafile ‘D:\oracle\user\owen_data.dbf‘
size 500m
autoextend on
next 20m maxsize 2000m
建立使用者並指定資料表空間
create user owen identified by 123
default tablespace owen_data
temporary tablespace owen_temp;
給該使用者解鎖
alter user owen account unlock;
給使用者授權
grant connect,resource to owen;
以dba角色查詢指定使用者的資料表空間(username必須大寫,必須使用單引號)
select user_id,username,default_tablespace from dba_users where username = ‘OWEN‘;
查詢所有資料表空間的資訊
select tablespace_name,status,allocation_type from dba_tablespaces;
修改資料表空間名稱
alter tablespace owen_data rename to new_owen_data;
刪除資料表空間,僅刪除資料表空間的記錄
drop tablespace owen_data;
刪除資料表空間及資料表空間檔案
drop tablespace owen_data including contents and datafiles;
實體(表、索引、視圖、序列)許可權有哪些?
select,update,insert,alter,index,delete,all(all包括所有許可權)
sys建立了一張表 t_test
sys給使用者lp授予了select t_test表的許可權
grant select on t_test to lp;
conn lp/1;
查詢該表
select * from sys.t_test;
給使用者授予這張表所有操作的許可權
grant all on t_test to lp;
添加記錄
insert into sys.t_test(name) values (‘owen‘);
Oracle資料庫學習第一天