一、管理員身份登陸:sqlplus/nolog--->conn/as sysdbasql
二、普通用戶登陸:sqlplus/nolog---->conn 用戶名/密碼數據庫
三、管理員切換到普通用戶:conn 用戶名/密碼session
四、普通用戶切換到管理人員:conn sys as sysdba,而後輸入密碼回車oracle
Connect角色---》普通用戶ide |
CONNECT SESSION-修改會話函數 Create cluster--創建簇族ui Create database link--創建數據庫鏈接spa Create sequence--創建序列操作系統 Create session--創建會話日誌 Create synonym--創建同義詞 Create view--創建視圖 |
Resource角色--》開發人員 |
Create cluster--創建簇族 Create procedure--創建過程 Create sequence--創建序列 Create table--建表 Create trigger--創建觸發器 Create type--創建類型 |
Dba角色--》管理員【具有全部系統權限,可是沒法啓動和關閉數據庫】 |
備份任何表、執行任何操做、查詢任何表 |
建立角色:create role角色名 not identified(創建公用角色)/create role 角色名 identified by密碼(創建私用角色)
三、角色受權:
3.1建立用戶沒有分配任何權限的時候,oracle自帶的上sqlplus上登陸該用戶會報錯
3.2 grant 權限名稱 to 角色名【注意:系統權限unlimited tablespace 和對象權限with grant option選項不能賦予給角色 】
四、顯示角色信息
4.1查詢角色信息:select * from role_sys_privs where role = '角色名稱'
4.2 查詢全部的角色:select * from dba_roles
4.3查詢角色系統權限:select privilege,admin_option from role_sys_privs whererole='角色名'
4.4查詢角色對象具備的權限:select privilege,admin_option from dba_tab_privs where role='角色名'
4.5查詢用戶具備角色以及默認角色:select grant_role from dba_sys_privs where grantee='用戶名'
4.6將角色分配給用戶:grant 角色名 to 用戶名 with admin option[加上with admin option是爲了用戶能夠將system分配給它的角色分配給別的其餘用戶]
4.7刪除角色:drop role角色名稱
(1)查看oracle系統權限:select * from sys_privilege_map
(2)分配權限:grant 權限名稱1,權限名稱2 to 用戶名 with admin option
(3)回收系統權限:revoke create session from 用戶名
前提:Smith用戶訪問scott.emp表
(1)經常使用的對象權限:alter、delete、select、insert、update、index、reference引用、execute
(2)查看對象權限:select distinct privilege from scott.emp
(3)授予對象權限:grant select on emp to monkey --受權查詢權限給monkey/grant delete on emp to monkey--受權刪除權限給monkey【也能夠一次性授予權限:grant all on em to monkey】
(4)授予更具體的權限(好比對列的操做):grant update on emp(sal) to monkey---受權monkey用戶emp表sal列的修改權限
(5)授予execute權限[用戶要執行其餘的方案的包、過程、函數必需要有execute權限]
(6)授予index權限[用戶在表scott.emp表上創建索引,須要index權限]
(7)使用with grant option選項【該選項用於轉授對象權限,只能授予用戶,不能授予角色】
4.1建立用戶:create user 用戶名 identifiled by 密碼
4.2刪除用戶:drop user 用戶名
4.3查看全部用戶:select * from dba_users/all_users或者select * from user_users
4.4查看用戶角色
(1)當前用戶被激活的角色:select * from session_roles
(2)當前用戶被授予的角色:select * from user_role_privs
(3)所有用戶被授予的角色:select * from dba_role_privs
(4)查看某個用戶擁有的角色:select * from dba_role_privs where grantee='用戶名'
表空間--》用戶--》表
一、建表空間:create tablespace 表間名 datafile '數據文件名【路徑能夠沿用系統自帶數據文件,可是記得修改文件名】' size 表空間大小
Oracle數據庫:數據庫的物理結構是由數據庫的操做系統文件所決定,每個Oracle數據庫是由三種類型的文件組成:數據文件
[select * from v$logfile]、日誌文件和控制文件[查看控制文件存放地址:select name from v$controlfile]。數據庫的文件爲數據庫信息提供真正的物理存儲(就是數據文件)
oracle物理數據文件【查看數據文件:select name v$datafile】
一個oracle數據庫有一個或多個數據文件
一個數據文件只與一個數據庫鏈接
一旦創建,數據文件只增不減
一個表空間由一個或多個數據文件組成
建用戶:create user 用戶名 identified by 密碼 default tablespace 表空間
給用戶受權:grant connect ,resource to 用戶名[grant dba to 用戶名]
建表:create table 表名
(1)、案例:
create tablespace data_test datafile 'D:\APP\YITOP\ORADATA\ORCL\TEST.DBF' size 2000M;
Tablespace created【建表空間和數據文件】
create user wangt identified by wtwrws666 default tablespace data_test;【建用戶】
grant connect,resource to wangt;和grant dba to wangt;
conn wangt/wtwrws666[從管理員切換到普通用戶]
建表:語法格式alter table 表名 add constraint 約束名 約束內容【alter table info add constraint ck_info_age check(age>=0and age<=100)】
修改表
重命名錶:rename 表名 to 新表名
向表中添加註釋:comment on table 表名 is ‘註釋文字’
更新表數據:update 表名 set 列名=’新值’ where 條件
修改列
修改列名:alter table 表名 rename column 列名 to 新列名
向列中添加註釋:comment on column 表名.列名 is ‘註釋文字’
修改列的屬性:alter table 表名 modify 列名 varchar2(字符長度)/number(精度)/char(數據類型/default ‘默認值’);
插入數據到表中:insert into 表名 values(‘數據’,’’,’’,’’)
3.1刪除表字段
alter table 表名 drop column 字段名
語法:select[distinct] * |列名稱 [別名],列名稱 [列名], from表名稱[別名][where 過濾條件(s)][order by 字段[ASC|DESC],……]
(1)alter table 表名 add constraint 約束名(約束名簡寫_表名)約束(字段名)
例如:添加約束鍵:alter table INFOS add constraint ck_infos_check check(age>=0 and age<=100)
添加外鍵:alter table scores add constraint fk_scores_infos_stuid foregin key(stuid) references infos(stuid) references infos(stuid)
主鍵約束:alter table 表名 add constraint 約束名稱 primary key(列名)
外鍵約束: alter table 表名1 add constraint 約束名稱 foreign key(列名) references 表名2(列名)
檢查約束:alter table 表名 add constraint 約束名稱 check(檢查條件)
不爲空:alter table 表名 add constraint 約束名稱 not null(列名)
惟一約束:alter table 表名 add constraint 約束名稱 unique(列名)
默認值約束:alter table 表名 add constraint 約束名稱 default ‘默認值’
給列添加約束
alter table 表名 add 字段名+字段約束