实验四总结报告.docx
《实验四总结报告.docx》由会员分享,可在线阅读,更多相关《实验四总结报告.docx(19页珍藏版)》请在冰豆网上搜索。
实验四总结报告
《数据库原理与应用》实验报告
实验名称:
实验四
班级:
软件工程
学号:
姓名:
一、实验目的
(1)了解Oracle数据库中的用户管理,模式,权限管理和角色管理。
(2)掌握为用户分配权限的方法。
(3)了解为不同用户分配不同权限的目的及原因。
二、实验过程
1.用系统帐户sys登录数据库,分别创建数据库内部用户user_one和user_two,创建时自己为用户分配帐户口令。
createuseruser_one
identifiedby980916
defaulttablespaceusers
temporarytablespacetemp
quotaunlimitedonusers;
createuseruser_two
identifiedby980916
defaulttablespaceusers
temporarytablespacetemp
quotaunlimitedonusers;
2.为了使两位用户登录数据库请为其授予相应的权限。
grantcreatesessiontouser_one,user_two;
3.授予用户user_one在自己模式下创建表的权限,在任何模式下删除表的权限,授予用户user_two可以在任何模式下创建表的权限,查询任何模式下表中数据的权限和在任何模式下创建视图的权限。
grantcreatetable,dropanytabletouser_one;
grantcreateanytable,selectanytable,createanyviewtouser_two;
4.分别用user_one和user_two登录,写出相应的SQL语句验证为其授予的权限。
(如果建立的表中有主键约束,需要预先授予user_one和user_two用户createanyindex的权限。
)
grantcreateanyindextouser_one,user_two;
在user_one中建表A
createtablea(
xnumber,
ydate);
在user_two中建表B
createtableb(
xnumber,
ydate);
在user_two中查询表A
select*fromuser_one.a;
从user_one中删除表B
droptableuser_two.b;
在user_two中查询表B
Select*fromb;
在user_two中建立视图VIEW_A
createviewview_a(x,y)
asselectx,y
fromb;
5.用系统帐户sys登录数据库,创建用户user_three,将角色权限DBA授予用户user_three,并将S、P、J、SPJ四张表导入到user_three模式下。
createuseruser_three
identifiedby980916
defaulttablespaceusers
temporarytablespacetemp
quotaunlimitedonusers;
grantdbatouser_three;
6.使用user_three登录,完成如下授权,在user_one和user_two用户下执行相应的SQL语句验证授权是否成功。
(1)把对表S的INSERT权力授予用户user_one,并允许他再将此权限授予其他用户。
grantinsertonstouser_onewithgrantoption;
在user_one中插入数据
insertintouser_three.s(sno,sname,city,sphone)
values('1','a','湖北',null);
commit;
grantinsertonuser_three.stouser_two;
在user_two中插入数据
insertintouser_three.s(sno,sname,city,sphone)
values('2','b','湖北',null);
commit;
(2)用户user_two对S,P,J三个表有SELECT和INSERT权力
grantselect,insertonstouser_two;
grantselect,insertonptouser_two;
grantselect,insertonjtouser_two;
从user_two中查询表S
select*fromuser_three.s;
从user_two中给表S插入数据
insertintouser_three.s(sno,sname,city,sphone)
values('3','c','湖北',null);
commit;
(3)用户user_one对SPJ表有DELETE权力,对QTY字段具有UPDATE权力。
grantdelete,update(qty)onspjtouser_one;
在user_one中删除sno为s1的数据
deletefromuser_three.spjwheresno='S1';
commit;
在user_one中将sno为s2的数据的qty改为0
updateuser_three.spjsetqty=0wheresno='S2';
commit;
(4)收回user_one对S表的插入权限。
revokeinsertonsfromuser_one;
尝试在user_one中插入数据
insertintouser_three.s(sno,sname,city,sphone)
values('3','d','湖北',null);
commit;
7.把对用户user_two授予的所有权限收回,只保留登录权限。
(系统权限和对象权限应该分别收回)
revokeselect,insertonsfromuser_two;
revokeselect,insertonpfromuser_two;
revokeselect,insertonjfromuser_two;
revokecreateanyindex,createanytable,createanyview,selectanytablefromuser_two;
尝试在user_two中创建表C
createtablec(
xnumber,
ydate);
8.用系统帐户sys登录数据库,创建用户user_four,将角色权限DBA授予此用户,在user_four的模式下导入Sudent、Course和SC表。
createuseruser_four
identifiedby980916
defaulttablespaceusers
temporarytablespacetemp
quotaunlimitedonusers;
grantdbatouser_four;
9.使用user_four登录,创建角色STUDBA,将修改Student、Course、SC表结构的权限,插入、删除、修改和查询三张表中数据的权限授予角色STUDBA,将角色的权限授予user_one和user_two。
createrolestudba;
grantalter,insert,delete,update,selectonstostudba;
grantalter,insert,delete,update,selectonctostudba;
grantalter,insert,delete,update,selectonsctostudba;
grantstudbatouser_one,user_two;
commit;
10.对于通过STUDBA角色授予的权限,在user_one和user_two用户下执行相应的SQL语句对权限进行验证。
修改表权限验证
altertableuser_four.caddcollagevarchar2(40);
commit;
select*fromuser_four.c;
更新数据验证
updateuser_four.ssetmajor='软件工程'wheremajor='植物保护';
select*fromuser_four.swheremajor='植物保护';
插入数据验证
insertintouser_four.sc(sno,cno,grade)
values(103000,300,100);
commit;
select*fromuser_four.scwheresno=103000andcno=300;
删除数据验证
deletefromuser_four.scwheresno=103000andcno=300;
commit;
select*fromuser_four.scwheresno=103000andcno=300;
三、实验总结