oracle--修改权限

用户: 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 同义词名

猜你喜欢

转载自www.cnblogs.com/fqqwz/p/11636768.html