当前位置:文档之家› 实验3:数据库安全性

实验3:数据库安全性

实验3:数据库安全性第1个实验.安全性定义——第5章实验八使用订单数据库完成下面的实验内容:(1) 分别创建登录账号user01、user02,其密码皆为p888888,并设置为订单数据库OrderDB的用户。

sp_addlogin'user01','p888888','orderdb'sp_addlogin'user02','p888888','orderdb'(2) 创建登录账号login03,并加入到OrderDB数据库中,其用户名为user03。

sp_adduser'user03','login03'(3) 将员工表的所有权限授予全部用户。

grant all privileges on customer to public(4) 授予user03用户对Product表的查询权限,对Employee表的编号、名称的查询和更新权限。

grant select on product to login03grantselect(employeeno,employeename),update(employeeno,employeename)on employee to login03(5) 创建角色r3、r4,将订单明细表所有列的SELECT权限、UNIT_PRICE列的UPDA TE 权限授予r3。

sp_addrole'r3'sp_addrole'r4'grant select,update(price)on orderdetail to r3(6) 收回全部用户对员工表的所有权限。

revoke all on employee from public(7) 将user01、user02两个用户赋予r3角色。

sp_addrolemember user01,r3sp_addrolemember user02,r3(8) 收回user02对订单明细表所有列的SELECT权限。

sp_addrole user02revoke select on orderdetail from user02(9) 在当前数据库中删除角色r4。

sp_droprole r4(10) 授予user01建表和建视图的权限,user01用户分别建立一张表和一个视图(表和视图自定),然后将该表和视图的查询权限授予user02和user03。

由于数据库中存在user01而user01的密码未知user01用user04 代替grant create view to user04创建表格Customercreate table Customer(customerNo char(9)not null primary key,/*客户号*/ check(customerNo like'[C][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),customerName varchar(40)not null,/*客户名称*/ telephone varchar(20)not null,/*客户电话*/ address char(40)not null,/*客户住址*/ zip char(6)null/*邮政编码*/ )创建视图Customernocreate view Customerno asselect customerno,customernamefrom customergrant select on customer to user02grant select on customerno to user02grant select on customer to user03grant select on customerno to user03第2个实验.安全性检查——第5章实验九使用订单数据库完成下面的实验,记录详细的操作过程:(1)用户user07在订单数据库中创建一张表Table1。

sp_addlogin'user07','123456','orderdb'(master 中)sp_adduser user07,user07(orderdb中)grant create table to user07create table Tabel (productNo char(9)not null primary key,/*商品编号*/ productName varchar(40)not null,/*商品名称*/ productClass varchar(20)not null,/*商品类别*/ productPrice numeric(7,2)not null,/*商品定价*/)(2)用户user02对表Table1和表OrderDetail执行了插入和查询操作。

grant select to user02(sa 登录)grant insert to user02(3)用户user03建立两张表Table2和Table3和一个视图View1,然后将该表和视图的查询权限授予user05和user06,并具有转授权限。

1、sp_addlogin'user05','123456'(master)sp_addlogin'user06','123456' //创建用户2、 sp_adduser user05,user05(orderdetail)//添加用户sp_adduser user06,user063、 grant create table,create view to user03(sa登录 orderdb中)//赋予权限4、创建表Table2和Table3:create table table2(table2no char(10)not null primary key,table2name varchar(30)not null,)create table table3(table3no char(10)not null primary key,table3name varchar(30)not null,)5、创建视图View1:create view view1asselect table2nofrom table26、赋予user05 和user06权限grant select on table2 to user05 with grant optiongrant select on table3 to user05 with grant optiongrant select on table2 to user06 with grant optiongrant select on table3 to user06 with grant optiongrant select on view1 to user05 with grant optiongrant select on view1 to user06 with grant option(4)user06用户需要对Product表进行插入操作,然后查询Product表的所有记录。

1、权限授予:grant select,insert to user06(sa登录 orderdb 中)2、用户登录:3、操作:insert product values('P2008004','CPU','处理器','1000')select*from product(5)在订单数据库中创建两个角色r5和r6,角色r5具有创建表和视图的权限,角色r6具有对Customer表的查询、插入权限,Employee表的查询、更新和插入权限,OrderMaster 表的所有权限。

sp_addrole r5sp_addrole r6grant create table,create view to r5grant select,insert on customer to r6grant select,insert on employee to r6grant update on employee to r6grant all on ordermaster to r6(6)用户user05在订单数据库中插入一条客户信息,并查询了所有客户的订货记录。

1、权限授予grant insert,select to user05(sa登陆,orderdb)2、插入操作用user05登陆insert customer values('C20080002','长城科技有限公司','0791-897456','江西省南昌市经开区','330013')3、查询操作select a.customerno,a.customername,b.orderdate,b.ordersumfrom customer a left outer join ordermaster b on a.customerno=b.customerno(7)用户user05将user03用户创建的表和视图的查询权限授予了用户user07,user07用户对表Table2进行了插入操作。

1、user5登陆2、权限授予grant select on user03.table2 to user07grant select on user03.table3 to user07grant select on user03.view1 to user073、uer07登陆4、插入操作1)插入权限增加:grant insert on user03.table2 to user07(orderdb)2)插入操作insert user03.table2 values('0103304','张三')(8)user07用户具有角色r5,同时创建了表Table4。

1)角色授予sa登陆在orderdb中sp_addrolemember r5,user072)user07登陆创建create table table4(table4no char(10)not null primary key,table4name varchar(30)not null)。

相关主题