设为首页 加入收藏

TOP

Oracle数据库的安全性和完整性控制(一)
2017-01-02 08:14:51 】 浏览:290
Tags:Oracle 数据库 安全性 完整性 控制

(一) 授权
1. 以dba用户的身份登陆oracle,创建用户u1+学号后四位,u2+学号后四位。
SQL> create user u1_3985 identified by "123";
SQL> create user u2_3985 identified by "123";
SQL> create user u3_3985 identified by "123";
SQL> create user u4_3985 identified by "123";
2. 对1.中创建的用户授予connect,resource的权限。
SQL> grant connect,resource to u1_3985,u2_3985;
3. 用户jsj***把查询Student表权限授给用户u1+学号后四位,u1执行相应的查询。
SQL> grant select on student to u1_3985;
SQL> con u1_3985/123@orcl;
1) 查询jsj***用户的全体学生的详细记录。
SQL> select * from j2014213985.student ;
2) 查询jsj***用户的所有姓刘的学生的姓名、学号和性别。
SQL> select sname,sno,ssex from j2014213985.student where sname like '刘%';
3) 查询jsj***用户的名字中第二字为“勇”字的学生的姓名和学号。
SQL> select sname,sno from j2014213985.student where sname like '_明';
4. 用户jsj***把对Student表和Course表的全部权限授予用户u2+学号后四位,u3+学号后四位;u2+学号后四位用户修改jsj***的数据。
SQL> grant all privileges on student to u2_3985,u3_3985;
SQL> grant all privileges on course to u2_3985,u3_3985;
SQL> update j2014213985.student set sage=24 where sname='刘明';
5. 把对表SC的查询权限授予所有用户。
SQL> grant select on SC to public;
1) 查询选修了3号课程的学生的学号及其成绩,查询结果按分数的降序排列
SQL> con u1_3985/123@orcl;
SQL> select sno,grade from j2014213985.SC where cno=3 order by grade desc;
2) 查询各个课程号与相应的选课人数。
SQL> select cno,count(*) from j2014213985.SC group by cno;
6. 用户jsj***授予用户u4+学号后四位对student表的insert权限,并允许此权限传播。
SQL> con j2014213985/j123456@orcl;
SQL> grant insert on student to u4_3985 with grant option;
7. 用户u4+学号后四位将对表student的insert权限授予u5+学号后四位,并允许将权限转授给其他用户。(首先应该以u5+学号后四位的身份重新登陆数据库,然后再进行授权)
SQL> con u4_3985/123@orcl;
SQL> grant insert on j2014213985.student to u5_3985 with grant option;
SQL> con u5_3985/123@orcl;
SQL> grant insert on j2014213985.student to u1_3985 with grant option;
(二) 回收权限
1. 收回所有用户对表sc的查询权限
SQL> revoke select on SC from public;
2. 收回用户u4对student表的insert权限
SQL> revoke insert on student from u4_3985;
3. 在回收权限之后验证用户是否真正丧失了该权限(查询表,插入记录)
SQL> select * from j2014213985.SC;
select * from j2014213985.SC
ORA-00942: 表或视图不存在
SQL> insert into j2014213985.student values('201421','小屋','男',100,'MA');
insert into j2014213985.student values('201421','小屋','男',100,'MA')
ORA-00942: 表或视图不存在
(三) 角色
1. 创建一个角色
SQL> create role ro1;
2. 给角色授予权限
SQL> grant insert,update,select on student to ro1;
3. 将角色授予某一用户
SQL> grant ro1 to u1_3985;
4. 检查用户是否具有相应的权限
SQL> con u1_3985/123@orcl;
SQL> select * from j2014213985.student;
SQL> insert into j2014213985.student values('20070002','徐梅','女',29,'MA');
SQL> update j2014213985.student set sage=25 where sname='刘明';
检查此用户是否具有相应权限。
SQL> con j2014213985/j123456@orcl;
SQL> insert into student values('20070001','张悦','女',22,'MA');
SQL> select * from student;
SQL> update student set sage=18 where sname='刘明';
(四) 完整性
1. 建立部门表DEPT,要求部门名称Dname列取值唯一,部门编号Deptno列为主码
create table DEPT(
Deptno varchar(10) constraint a1 primary key,
Dname varchar(10) unique not null,
Dnum number(4));
(1)SQL> insert into DEPT values('201411','宏光实业',1000);
(2)SQL> insert into DEPT values('201412','宏光实业',2000);
insert into DEPT values('201412','宏光实业',2000)
ORA-00001: 违反唯一约束条件 (J2014213985.SYS_C0039963)
(3)SQL> insert into DEPT values('201411','长青实业',2000);
insert into DEPT values('201411','长青实业',2000)
ORA-00001: 违反唯一约束条件 (J2014213985.A1)
2. 建立学生登记表Student,要求学号在9000至9999之间,年龄<29,性别只能是’男’或’女’,姓名非空。
create table Student2(
sno number(10) check(sno>=9000 and sno<=9999),
sanme v

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PL/SQL插入记录:ORA-00001:违反.. 下一篇TOAD和PLSQL 默认日期显示、rowid..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目