首页 > 代码库 > 视图、序列、索引的创建及用户权限
视图、序列、索引的创建及用户权限
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;
视图、序列、索引的创建及用户权限