用戶: system / sys
1.select * from dba_users; 顯示所有用戶
1.創建用戶: create user A identified by 123456;
2.權限分配:
DBA:所有全部
resource:可以創建實體,不可以創建數據庫
connect :可以登錄
分配權限
grant connect, resource to 用戶名;//
grant all on 表名 to 用戶名;//all 增,刪,改,查
grant select,update on 表名 to 用戶名;
管理員:
select * from 用戶名.表名
commit;提交
刪除權限
revoke connect from 用戶名;
3.用戶的切換
conn 用戶/密碼
4.修改用戶密碼
alter user 用戶名 identified by 新密碼;
5.刪除用戶
drop user 用戶名;
注:在用戶名下以有表,或。。, 在刪除用戶前必需先將表刪除,再刪除用戶
視圖:用來保存查詢結束
1、創建視圖: 注,視圖的列必是表中存在的列名,列名不能重復
函數,算數運算,rumber... 但可以給它們取一個別名
如:
create view mydd as select mathe+10 as mathe from stu inner join course on stu.id = course.id where sex='女';
select * from mydd;
create view 視圖名 as 查詢語句;
create view stu_mathe as select first_name||''||last_name as "姓名", mathe from stu where mathe>60;
select * from stu_mathe;
如果用戶是普通用戶,需要先賦權限
grant create view to 用戶名;
create view 新視圖名 as select * from 表名 where name like 'd%';
2、修改視圖
create or replace view 視圖名 as 查詢語句;
create or replace view 原視圖名 as select * from 表名 where name like '%d%';
3、刪除視圖
drop view 視圖名;
索引: 用於提高查詢效率 , 表記錄多時(10W)
查詢結束在 5%,使用
create index 索引名 on 表名(字段名);
create index stu_index_first on stu(first_name);
select * from stu where first_name='王';
序列:是一個計數器
1、定義
create sequence 序列名
start with 1 //開始值
increment by 1 //步長
minvalue 1 //最小值
maxvalue // 最大值 , nomaxvalue
cycle //循環,nocycle
cache //緩存, nocache
create sequence mys
start with 1 //開始值
increment by 1 //步長
minvalue 1 //最小值
maxvalue // 最大值 , nomaxvalue
cycle //循環,nocycle
cache //緩存, nocache
2.使用, 主鍵
insert
update
序列名.nextval
id, name, age;
1 ddd 20
2 ddd 20
3 ddd 20
insert into stu values(mys.nextval,'ddd', 20)
insert into stu values(mys.nextval,'ddd', 20)
insert into stu values(mys.nextval,'ddd', 20)
mys.currval
同義詞:另一個用戶的表的別名 .
create synonym 同義詞名 for 用戶名.表名
兩個普通用戶,一個用戶使用另一個用戶中的表,視圖...
1.第一個普通用戶,需要具有connect, resource ,create synonym , 管理員授權
2.以第一個用戶登錄,創建同義詞
create synonym 同義詞名 for 第二個用戶名.表名
3.以第二個用戶登錄,將對表的操作權限給第一個用戶
grant select on 表名 to 第一個用戶名
grant all on 表名 to 第一個用戶名
4.以第一個用戶登錄,使用同義詞
select * from 同義詞名
drop synonym 同義詞名