1. 程式人生 > >視圖、序列、索引的創建及用戶權限

視圖、序列、索引的創建及用戶權限

當前 下一個 rem incr user ssi from 系列 sta


select * from scott.emp;
--創建視圖
create view waa as
select * from scott.emp;
drop view waa;
select * from wan;
--修改視圖 or replace view
create or replace view waa(ename) as
select ename||‘hfh‘ from scott.emp ;
--視圖中有 group by ,distinct ,rownum 時 不能使用delete
create view wan as
select sal from scott.emp group by sal ;
delete from wan;
--只讀視圖 不可以修改
create view wa as
select * from scott.emp where sal>3000
with read only ;
select * from wa;
insert into wa(empno) values (2);
drop view waa;
-- 創建系列
CREATE SEQUENCE dept_deptid_seq
INCREMENT BY 10 --增量
START WITH 50 --開始值
MAXVALUE 9999 --最大值
NOCACHE --不寫入內存
NOCYCLE; --不循環 到最大值結束

select dept_deptid_seq.nextval from dual ; --查詢下一個 先
select dept_deptid_seq.currval from dual ; --查詢當前值 後
--修改序列 增量 最大值 循環與否
alter sequence dept_deptid_seq
increment by 20
maxvalue 300
cycle ;
-- 刪除序列
drop sequence dept_deptid_seq;
--創建索引
create index suoyin
on wan(name); --在表的某一列創建索引
--刪除索引
drop index suoyin;

--用戶和權限
--創建用戶
create user scott --用戶名
identified by tiger; --密碼
-- 修改密碼
alter user scott
identified by tiger;
--創建角色
create role zu;
--為角色賦予權限
Grant create table ,create session,create view,create procedure
To zu;
--將角色賦予用戶
Grant zu To scott,num1,num2;











視圖、序列、索引的創建及用戶權限