sql语言用grant语句向用户授予操作权限,grant语句的一般格式为:
grant
<权限>[,<权限>]...
[on
<对象类型>
<对象名>]
to
<用户>[,<用户>]...
[with
grant
option];
其语义为:将对指定操作对象的指定操作权限授予指定的用户。
不同类型的操作对象有不同的操作权限,常见的操作权限如表3-4所示。
表3-4
不同对象类型允许的操作权限
对象
对象类型
操作权限
属性列
table
select,
insert,
update,
delete
all
privieges
视图
table
select,
insert,
update,
delete
all
privieges
基本表
table
select,
insert,
update,
alter,
index,delete
all
privieges
数据库
database
createtab
详细信息…
接受权限的用户可以是一个或多个具体用户,也可以是public即全体用户。
如果指定了with
grant
option子句,则获得某种权限的用户还可以把这种权限再授予别的用户。如果没有指定with
grant
option子句,则获得某种权限的用户只能使用该权限,但不能传播该权限。
例1
把查询student表权限授给用户u1
grant
select
on
table
student
to
u1;
例2
把对student表和course表的全部权限授予用户u2和u3
grant
all
priviliges
on
table
student,
course
to
u2,
u3;
例3
把对表sc的查询权限授予所有用户
grant
select
on
table
sc
to
public;
例4
把查询student表和修改学生学号的权限授给用户u4
详细信息…
这里实际上要授予u4用户的是对基本表student的select权限和对属性列sno的update权限。授予关于属性列的权限时必须明确指出相应属性列名。完成本授权操作的sql语句为:
grant
update(sno),
select
on
table
student
to
u4;
例5
把对表sc的insert权限授予u5用户,并允许他再将此权限授予其他用户
grant
insert
on
table
sc
to
u5
with
grant
option;
详细信息…
执行此sql语句后,u5不仅拥有了对表sc的insert权限,还可以传播此权限,即由u5用户发上述grant命令给其他用户。
例如u5可以将此权限授予u6:
grant
insert
on
table
sc
to
u6
with
grant
option;
同样,u6还可以将此权限授予u7:
grant
insert
on
table
sc
to
u7;
因为u6未给u7传播的权限,因此u7不能再传播此权限。
例6
dba把在数据库s_c中建立表的权限授予用户u8
grant
createtab
on
database
s_c
to
u8;
grant select on scott.Employees to user1,user2;
不需要TABLE 这个参数。 并且表要带用户。
grant select on employees to user1,user2
看例子:
GRANT SELECT
ON authors
TO public
go
GRANT INSERT, UPDATE, DELETE
ON authors
TO Mary, John, Tom